其他分享
首页 > 其他分享> > android-marginTop和marginBottom不适用于LinearLayout

android-marginTop和marginBottom不适用于LinearLayout

作者:互联网

主(容器)LinearLayout:

<LinearLayout
    android:id="@+id/LinearHome"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</LinearLayout>

子LinearLayouts(我通过增加新的动态布局来动态添加它们):

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/lnote"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp" />

有什么问题?

解决方法:

将inflate()方法的第二个参数设置为父级(主容器)

LinearLayout lNewNote = (LinearLayout) getLayoutInflater().inflate(R.layout.note_layout, HomeContainer); 
HomeContainer.addView(lNewNote);

我相信这对我有用. (我猜HomeContainer只是一个对象,而不是一个类)

标签:android-linearlayout,android
来源: https://codeday.me/bug/20191030/1964739.html