私は、デフォルトのアプリと非常によく似た、ある種のストップウォッチアプリを開発しています。これは、基本的な知識があることを確認するためだけに行っています。私の問題:ラップボタンを押した後、新しいレイアウトが作成され、tvDisplay(タイマーを表示するテキストビュー)の現在の値が新しいテキストビューに配置されます(以下のコードを参照)。動作しますが、動的に追加されたレイアウトを互いに分離して、全体の見栄えを良くしたいと思います。nlap LinearLayoutのパディングを設定しようとしましたが、機能しませんでした。setMargins()メソッドも見つかりませんでした。動的に追加された線形レイアウトの間にdpの空き領域を追加するにはどうすればよいですか?
XML:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LapHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="25dp"
android:layout_marginTop="20dp" >
<LinearLayout
android:id="@+id/lap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
java:
public void LapClick(View view) {
LinearLayout lap = (LinearLayout) findViewById(R.id.lap);
TextView disp = (TextView) findViewById(R.id.tvDisplay);
TextView ms = (TextView) findViewById(R.id.timerMs);
ScrollView.LayoutParams layoutParams = new ScrollView.LayoutParams(
ScrollView.LayoutParams.MATCH_PARENT,
ScrollView.LayoutParams.WRAP_CONTENT);
LinearLayout nlap = new LinearLayout(this);
nlap.setOrientation(LinearLayout.VERTICAL);
nlap.setLayoutParams(layoutParams);
nlap.setBackgroundColor(Color.parseColor("#C7C7C7"));
TextView value = new TextView(this);
value.setText(disp.getText().toString() + ms.getText().toString());
value.setTextColor(Color.parseColor("#A60101"));
value.setGravity(Gravity.CENTER);
nlap.addView(value);
lap.addView(nlap);
}