2011-12-20 20 views
0

最初の行に見出しがあり、その下にリストビューがあるレイアウトを作成する必要があります。見出しは左揃えにし、リストビューは全幅に一致させる必要があります。このために、私は次のXMLを使用しています。Androidテーブルのレイアウトの幅の問題

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/splashContent" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:background="#7A0225" 
    android:orientation="vertical" > 
    <TableRow 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="top|left" 
     android:layout_weight="0" 
     android:background="@drawable/search_bg_row1"> 
     <TextView 
      android:id="@+id/pcomparetitle" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:paddingBottom="4dp" 
      android:paddingLeft="10dip" 
      android:paddingRight="0dip" 
      android:paddingTop="10dp" 
      android:text="Price Comparison for ISBN: " 
      android:textColor="#FFFFFF" 
      android:background="#00FF00" 
      android:textSize="15sp" 
      android:textStyle="bold" > 
     </TextView> 
    </TableRow> 
    <TableRow 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="center_vertical|left" 
     android:background="@drawable/search_bg_row3"> 
     <ListView 
      android:id="@+id/pricelist" 
      android:background="#FF0000" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
     </ListView> 
    </TableRow> 
</TableLayout> 

ここで、リストビューは見出しの幅と同じです。見出しが高解像度ディスプレイの幅と比較して短いので、リストビューは部分的な幅をとっています。この問題を解決するには?

+1

あなたは自分のリストビューのヘッダを設定したい場合は、 'addHeaderView'方法があります。http:/は/stackoverflow.com/questions/2620177/android-adding-static-header-to-the-top-of-a-listactivity – Dalmas

答えて

2

私はuがtextviewとその下list viewを表示するために、これは十分にあると思う:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/splashContent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#7A0225" 
    android:orientation="vertical" > 

     <TextView 
      android:id="@+id/pcomparetitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Price Comparison for ISBN: " 
      android:textColor="#FFFFFF" 
      android:background="#00FF00" 
      android:textSize="15sp" 
      android:textStyle="bold" > 
     </TextView> 

     <ListView 
      android:id="@+id/pricelist" 
      android:background="#FF0000" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
     </ListView> 
    </LinearLayout>