2017-10-11 68 views
0

我在我的TableRow中有兩個TextView,但其中一個文本很大。我想第一TextView浮到TableRow頂部:將TextView浮動到TableRow的頂部

<TableRow 
     android:id="@+id/trLocation" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/location"/> 

     <TextView android:layout_width="wrap_content" 
        android:textSize="50dp" 
        android:layout_height="wrap_content" 
        android:text="1234" 
        android:id="@+id/tvLocation" 
        android:layout_weight="1" 
      /> 
    </TableRow> 

我嘗試使用layout_gravitygravity,但他們都沒有任何效果。

回答

1

試試這個

<?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" 
    android:orientation="vertical"> 


    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:text="Small Text" 
     android:gravity="left|center" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

    <TableRow 
     android:id="@+id/trLocation" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <TextView 
      android:id="@+id/tvLocation" 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" 
      android:layout_weight="1" 
      android:text="1234" 
      android:textSize="50dp" /> 
    </TableRow> 

</RelativeLayout> 
+0

這將引入一定的冗餘度。當我改變文字大小時,我還必須更改兩個'layout_height'。 –

+0

如果您使用dim.xml來設置數字值(如textSize),則不需要在兩處進行更改 –