0

layout_margins が設定された LinearLayout を持つカスタム xml を作成しました。グラフィックレイアウトを表示するとマージンが表示されますが、別のアクティビティでこのビューを ScrollView 内の LinearLayout に追加しようとするとマージンがありません。これがカスタムxmlコードです....

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/run_background"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp">

<TextView
    android:id="@+id/tvRunName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@android:color/white"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:layout_gravity="center"
    android:layout_marginTop="10dp" />

ビューを追加するコードは次のとおりです....

        for(int x = 0; x < runs.size(); x++){

        inflater = (LayoutInflater)this.getSystemService(this.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.run_layout, null);


        TextView name = (TextView) layout.findViewById(R.id.tvRunName);
        name.setText(runs.get(x).getName());

        llRuns.addView(layout);
    }

ビューを好きなように離すにはどうすればよいですか?

4

1 に答える 1

1

LayoutParams は、レイアウトの膨張中に含まれていません。レイアウトを膨張させながら、3 番目のパラメーターを追加してみてください。

View layout = inflater.inflate(R.layout.run_layout, null, false);
于 2013-08-09T16:25:29.117 に答える