2016-09-16 54 views
0


为什么线性布局不填满整个屏幕?
正如你所看到的,我在线性布局中使用匹配父项。
如果我删除滚动条没有任何变化。该按钮不在屏幕的底部。
main_activity.xml:线性布局不填满整个屏幕

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/black" 
    tools:context="com.sarahp.demo.MainActivity"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout         ----------> HERE 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/textview_demo" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginBottom="32dp" 
       android:layout_marginTop="32dp" 
       android:text="@string/demo" 
       android:textSize="42dp"/> 

      <RelativeLayout 
       android:id="@+id/fragment_container_a" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"/> 

      <RelativeLayout 
       android:id="@+id/fragment_container_b" 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:layout_alignParentBottom="true" 
       android:background="@color/transparent"/> 

     </LinearLayout> 
    </ScrollView>  
</RelativeLayout> 

F A是片段部分。 enter image description here

+0

尽量给fragment_container_a,高度= 0和体重= 1 – Flo

+0

仍有底部 –

+0

的空间你怎么想你布局? –

回答

1

android:fillViewport="true"给你的ScrollView。

您的xml如下所示。 Main_Activity.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 


     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="40dp" 
      android:text="Test Demo" 
      android:textStyle="bold" 
      android:gravity="center"/> 

     <RelativeLayout 
      android:id="@+id/fragment1" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.5" 
      android:background="@drawable/border_image"> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="100dp" 
       android:gravity="center" 
       android:text="Test text Fragement1" /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/fragment2" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.5" 
      > 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="100dp" 
       android:gravity="center" 
       android:text="Test text Fragement2" /> 
     </RelativeLayout> 

    </LinearLayout> 
</ScrollView> 
</RelativeLayout> 
0

删除相对布局

<ScrollView 

     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout         
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/textview_demo" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginBottom="32dp" 
       android:layout_marginTop="32dp" 
       android:text="@string/demo" 
       android:textSize="42dp"/> 

      <RelativeLayout 
       android:id="@+id/fragment_container_a" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"/> 

      <RelativeLayout 
       android:id="@+id/fragment_container_b" 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:layout_alignParentBottom="true" 
       android:background="@color/transparent"/> 

     </LinearLayout> 
    </ScrollView>