2010-12-27 7 views
0

レイアウトの残っているものを埋める作る:彼らは真ん中のTextViewがレイアウトの残っているものを埋める必要があり、このようなレイアウトを持っている場合ハウツー要素はこれまでのところ、私はこのレイアウトのコードを持って

<?xml version="1.0" encoding="utf-8"?> 

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

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="48dip" 
     android:background="#FFFFFF" > 

     <ImageView 
      android:layout_weight="1" 
      android:layout_width="40dip" 
      android:layout_height="40dip" 
      android:layout_gravity="center_vertical" 
      android:src="@drawable/icon" /> 

     <TextView 
      android:layout_weight="1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:text="text" /> 

     <TextView 
      android:layout_weight="1" 
      android:layout_width="40dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:text="text" /> 

    </LinearLayout> 

</LinearLayout> 

は、人々は何をしますか?ここでは40dip幅のImageViewと40dip幅のTextViewがあります。だから私は左のものを埋めるために中間のTextViewを取得しようとしています。上記のコードは私が得る限りです。私は左に何が残っているのかを補うために中間のTextViewを取得しました。左にあるImageViewを40dipよりも小さくするように設定しました。

ここでは何をしますか? Androidでのレイアウトは簡単ではありません。

私がやりたいことは、マーケットのリストのようなリストを作成することです。左にアイコン、中央に2行のテキスト、右に追加の情報があります。これを行う方法の例はありますか?

私は、次のレイアウトは何をしたいあなたを与えるだろうと思い

答えて

4

<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="1"> 

<TableRow android:layout_width="fill_parent"> 

    <ImageView android:src="@drawable/icon" /> 

    <TextView 
     android:padding="3dip" 
     android:gravity="left" 
     android:text="Stretched text" 
     /> 

    <TextView 
     android:padding="3dip" 
     android:gravity="left" 
     android:text="LeftOver" 
     /> 
</TableRow> 

あなたがのLinearLayoutで作業を続けたい場合は、重力のプロパティを使用する必要があります。以下はまた、あなたが望むものをあなたに与えます:

また
<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="48dip" 
    android:background="#dddddd" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:src="@drawable/icon" /> 

     <TextView 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:text="Stretched Text" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="right" 
      android:text="text" /> 

</LinearLayout> 

、いくつかのレイアウト例についてview - API Demosをチェックアウト。

+1

Thanx!私は今、そのトリックが何であるかを見ます。ストレッチする必要がある要素に対してのみlayout_weightを設定します。私は3つの要素すべてでそれを持っていた。 – Espen

関連する問題