无法在其他xml中对齐包含布局的底部要素

时间:2014-11-27 07:01:44

标签: android android-layout alignment

我有一个页脚xml文件。我将该文件包含在所有其他文件中,如....

 <RelativeLayout
     android:id="@+id/footer"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true">

     <include layout="@layout/footer" />
 </RelativeLayout>

但是我收到类似于&#34; LinearLayout中无效的布局参数的警告:layout_alignParentBottom&#34;          任何人都可以告诉我如何在不使用尺寸的情况下将包含的xml对齐在底部

2 个答案:

答案 0 :(得分:0)

您无法在LinearLayout中使用属性alignParentBottom。这就是RelativeLayout。

对于LinearLayout,您可以使用layout_gravity

<LinearLayout> <!-- container LinearLayout -->
    <LinearLayout
         android:id="@+id/footer"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_gravity="bottom">

         <include layout="@layout/footer" />
     </LinearLayout>
</LinearLayout>

希望这有帮助。

答案 1 :(得分:0)

此代码会将您的资料带到底部(页脚)。

这将是你的Footer XML。

footer.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/footer_test"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:gravity="bottom"
            android:layout_alignParentBottom="true"> 
      </RelativeLayout>

现在将您的页脚xml包含在您想要的布局中。

,例如,

abc.xml

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

        <include layout="@layout/footer"
         android:id="@+id/footer_test"/>

</LinearLayout>

希望这有助于:)