【问题标题】:How to place a Linearlayout at bottom inside a Relativelayout in android如何在android中的Relativelayout内底部放置一个Linearlayout
【发布时间】:2012-06-02 09:53:54
【问题描述】:

我需要在relativelayout 的底部放置一个线性布局,它是xml 中最顶层的父级。我怎样才能做到这一点?

请帮帮我。

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout .......   <<--- this should occupy total available space
</Relativelayout
 <Linearlayout .......     <<-- this should place at bottom always with height 50dp
 </LineaLayout>
 </ReltiveLayout>

【问题讨论】:

  • 只是一个提示:在发布问题之前,请做一些谷歌搜索或检查类似的问题。

标签: android android-layout android-relativelayout android-linearlayout


【解决方案1】:

请试试这个:

<LinearLayout android:layout_alignParentBottom="true" android:layout_height="50dp" android:layout_width="wrap_content">
</LinearLayout>

您可以通过上述属性在 xml 中底部对齐。

【讨论】:

    【解决方案2】:

    试试这个:

     <?xml version="1.0" encoding="utf-8"?>
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:minHeight="?android:attr/listPreferredItemHeight" >
     <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="119dp" >
     </RelativeLayout>
    
     <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" >
     </LinearLayout>
    
    </RelativeLayout>
    

    【讨论】:

      【解决方案3】:

      使用这个

       <?xml version="1.0" encoding="utf-8"?> 
       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"      >
      <RelativeLayout
          android:id="@+id/relativeLayout"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_alignParentTop="true"
          android:background="#ff00ff00"
          android:layout_centerHorizontal="true" >
      </RelativeLayout>
      <LinearLayout
          android:id="@+id/linearLayout"
          android:layout_width="wrap_content"
          android:layout_height="50dp"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:background="#ffff0000"
          android:layout_alignParentRight="true" >
      
      </LinearLayout>
      

      【讨论】:

        【解决方案4】:

        找到了更通用的方法

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".nestedLayoutActivity" >
        
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="seebelow" />
        
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal" >
        
                <Button
                    android:id="@+id/new_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="80dp"
                    android:layout_gravity="bottom"
                    android:text="@string/New" />
        
                <Button
                    android:id="@+id/list_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:text="@string/list" />
        
                <Button
                    android:id="@+id/more_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:text="@string/more" />
            </LinearLayout>
        
        
        </RelativeLayout>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-11-09
          • 2011-03-30
          • 1970-01-01
          • 1970-01-01
          • 2015-02-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多