2013-12-23 201 views
2

我制作了一个假人View并将其填充重量= 1为什么我的android:layout_weight不起作用?

我希望所有额外的空间都可以进入该视图,但它在现实中不会发生。

我错过了什么?

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res/com.me" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:gravity="center_horizontal"> 

     <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" > 

       <com.m.view.text.MyTextView 
        android:id="@+id/whyResgisterHeaderText" 
        style="@style/textOnBg" 
        android:layout_marginBottom="10dp" 
        android:layout_marginTop="30dp" 
        android:text="WHY REGISTER?" 
        android:textAllCaps="true" 
        android:textColor="@android:color/white" 
        app:font_type="varela" /> 

       <com.m.view.text.MyTextView 
        android:id="@+id/whyResgisterBodyText" 
        style="@style/textOnBg" 
        android:lineSpacingMultiplier="1.2" 
        android:text="first line\nsecond line\nthird line\nforth line" 
        android:textStyle="italic" /> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dp" 
        android:layout_marginTop="20dp" 
        android:src="@drawable/signup_illu_why" /> 

       <View 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" /> 

       <LinearLayout 
        android:id="@+id/gotItAction" 
        android:layout_width="283dp" 
        android:layout_height="52dp" 
        android:layout_marginBottom="20dp" 
        android:layout_marginLeft="5dp" 
        android:layout_marginRight="5dp" 
        android:layout_marginTop="10dp" 
        android:background="@drawable/btn_selector" 
        android:clickable="true" 
        android:gravity="center" 
        android:orientation="horizontal"> 

        <com.m.view.text.MyTextView 
         android:id="@+id/goItText" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:gravity="center" 
         android:text="Got it" 
         android:textColor="#00bcfe" 
         android:textSize="16dp" 
         android:textStyle="italic" /> 
       </LinearLayout> 
      </LinearLayout> 
     </ScrollView> 
    </RelativeLayout> 
+0

重量不相对布局 –

回答

0

我想你如果你正在使用类似LinearLayout父元素,并使用layout_weight里面在你的第一个LinearLayout中添加android:weightSum="1.0"(其中包含的观点具有重量的)

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:weightSum="1.0" 
      android:orientation="vertical" > 
+0

内工作,它没有用是这样的。我会尝试 –

+0

不。相同的结果 –

0

他们的child element你可能会得到期望的结果。但是,如果您有ScrollView作为主要父项,并且在其child element之内使用layout_weight属性,则可能不会证明这是一个好结果。 Bcs,ScrollView是无止境的,它只会在其子元素完成的时候结束。所以,很明显如果你使用weight属性,那么Android可能无法找出你想要结束scroll的地方并且行为不当。

因此,尽量保留LinearLayout其中包含TextView(与Got It文本)在主布局的底部。将LinearLayout删除并将其粘贴在ScrollView之外,以便它将在滚动的底部。

试试这个..

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res/com.me" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center_horizontal" 
    android:orientation="vertical" > 

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

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

      <com.m.view.text.MyTextView 
       android:id="@+id/whyResgisterHeaderText" 
       android:layout_marginBottom="10dp" 
       android:layout_marginTop="30dp" 
       android:text="WHY REGISTER?" 
       style="@style/textOnBg" 
       android:textAllCaps="true" 
       android:textColor="@android:color/white" 
       app:font_type="varela"/> 

      <com.m.view.text.MyTextView 
       android:id="@+id/whyResgisterBodyText" 
       style="@style/textOnBg" 
       android:lineSpacingMultiplier="1.2" 
       android:text="first line\nsecond line\nthird line\nforth line" 
       android:textStyle="italic" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="20dp" 
       android:layout_marginTop="20dp" 
       android:src="@drawable/signup_illu_why" /> 
     </LinearLayout> 
    </ScrollView> 

    <LinearLayout 
     android:id="@+id/gotItAction" 
     android:layout_width="283dp" 
     android:layout_height="52dp" 
     android:layout_alignParentBottom="true" 
     android:layout_centerInParent="true" 
     android:layout_marginBottom="20dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="10dp" 
     android:background="@drawable/btn_selector" 
     android:clickable="true" 
     android:gravity="center" 
     android:orientation="horizontal" > 

     <com.m.view.text.MyTextView 
      android:id="@+id/goItText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:text="Got it" 
      android:textColor="#00bcfe" 
      android:textSize="16dp" 
      android:textStyle="italic" /> 
    </LinearLayout> 

</RelativeLayout> 
+0

你做了什么? –

+0

@EladBenda检查我的编辑的解释.. – Hariharan