将屏幕划分为两个TextView

时间:2015-06-15 13:27:09

标签: android textview tablelayout

在我的android布局中有两个textview。每个在不同的表行。我想平分这些行。第一个textview是基于GCM的文本,第二个是harcoded。该行应该根据文本的大小平均分配,所以我也放了scrollview,我需要它。

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/TableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
android:background="@drawable/border"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".LiveMsg" >


<TableRow
    android:id="@+id/tableRow1"
   android:layout_height = "100dp"
    android:layout_weight = "1"
    android:paddingBottom="20dip"
    android:gravity="center" >


<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0.97"
    android:id="@+id/scrollview1"
    android:scrollbars="vertical" >

<TextView
    android:id="@+id/lblMessage"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#FFFFFF"
    android:textSize="30sp"
    android:text="" />
</ScrollView>
</TableRow>

<TableRow
    android:id="@+id/tableRow2"
   android:layout_height = "100dp"
    android:layout_weight = "1"
    android:paddingBottom="20dip"
    android:gravity="center"  >


<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0.97"
    android:id="@+id/scrollview2"
    android:scrollbars="vertical" >

<TextView
    android:id="@+id/tableRow5"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#FFFF00"
    android:textSize="20sp"
    android:text="LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE....LONG TEXT GOES HERE.... " />
</ScrollView>
</TableRow>

它应该适用于所有屏幕尺寸。我可以这样做吗?

1 个答案:

答案 0 :(得分:-1)

像这样替换你的TableRow:

<TableRow
  android:id="@+id/tableRow2"
  android:layout_width = "match_parent"
  android:layout_height = "match_parent"
  android:layout_weight = "1"
  android:paddingBottom="20dip"
  android:gravity="center">

还从滚动视图中删除权重。您也可以使用两个具有上述相同技巧的滚动视图。