2013-12-21 19 views
0

我希望我的文字留在每個屏幕大小的底部。我嘗試過使用margintop,並在中間添加了一個空格,以將TextView推到底部,但在其他屏幕上無法使用。這是我的代碼和屏幕。Android:我如何將文字放在底部?

圖片:http://i.stack.imgur.com/4nJzh.png

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

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

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:src="@drawable/browse" /> 

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

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" > 

       <TextView 
        android:id="@+id/textView1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Name :" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 

       <TextView 
        android:id="@+id/textView4" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Medium Text" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" > 

       <TextView 
        android:id="@+id/textView5" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Password :" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 

       <TextView 
        android:id="@+id/textView2" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Medium Text" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 
      </LinearLayout> 

     </LinearLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </LinearLayout> 

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

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Gender :" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/textView7" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
    </LinearLayout> 

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

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:layout_weight="1" 
      android:text="Ph No :" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/textView8" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:text="Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

    </LinearLayout> 

    <android.support.v7.widget.Space 
     android:id="@+id/space1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <android.support.v7.widget.Space 
     android:id="@+id/space2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:id="@+id/textView10" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:text="Small Text" 

     android:textAppearance="?android:attr/textAppearanceSmall" /> 

</LinearLayout> 
+1

使用相對佈局,將有所幫助 –

+0

你可以使用這個重量.. – mayuri

回答

0

使用weight = 0爲TextView的,或者使用RelativeLayout父母,使你的TextView alightParentBottom="true"

+1

OH它的工作原理!謝謝 :) –

0

試試這個..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

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

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

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:adjustViewBounds="true" 
       android:src="@drawable/browse" /> 

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

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" > 

        <TextView 
         android:id="@+id/textView1" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="Name :" 
         android:textAppearance="?android:attr/textAppearanceMedium" /> 

        <TextView 
         android:id="@+id/textView4" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="Medium Text" 
         android:textAppearance="?android:attr/textAppearanceMedium" /> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" > 

        <TextView 
         android:id="@+id/textView5" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="Password :" 
         android:textAppearance="?android:attr/textAppearanceMedium" /> 

        <TextView 
         android:id="@+id/textView2" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="Medium Text" 
         android:textAppearance="?android:attr/textAppearanceMedium" /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:l="" > 
     </LinearLayout> 

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

      <TextView 
       android:id="@+id/textView6" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Gender :" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:id="@+id/textView7" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Medium Text" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
     </LinearLayout> 

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

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left" 
       android:layout_weight="1" 
       android:text="Ph No :" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:id="@+id/textView8" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right" 
       android:layout_weight="1" 
       android:text="Medium Text" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
     </LinearLayout> 

     <android.support.v7.widget.Space 
      android:id="@+id/space1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <android.support.v7.widget.Space 
      android:id="@+id/space2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/textView10" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="Small Text" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

</RelativeLayout> 
0

,你也可以使用這個

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="10" > 
    <LinearLayout 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
    <LinearLayout   
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:src="@drawable/ic_launcher" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" > 
       <TextView 
        android:id="@+id/textView1" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Name :" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 
       <TextView 
        android:id="@+id/textView4" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Medium Text" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 
      </LinearLayout> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" > 
       <TextView 
        android:id="@+id/textView5" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Password :" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 
       <TextView 
        android:id="@+id/textView2" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Medium Text" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Gender :" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
     <TextView 
      android:id="@+id/textView7" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:layout_weight="1" 
      android:text="Ph No :" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
     <TextView 
      android:id="@+id/textView8" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:text="Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
    </LinearLayout> 
    </LinearLayout> 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="9" 
    android:orientation="vertical" > 
    <TextView 
     android:id="@+id/textView10" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Small Text" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 
</LinearLayout> 
</LinearLayout> 
相關問題