2012-01-13 10 views
0

レイアウトファイルの場所のTextViewとボタンを使用しようとしています。Androidでウィジェットの行を配置する

Row 1: [ TextView (~2/3 of the screen) ] [ Button (~1/3 of the screen) ]

Row 2: [ TextView (~2/3 of the screen) ] [ Button (~1/3 of the screen) ]

Row 3: [ TextView (~2/3 of the screen) ] [ Button (~1/3 of the screen) ]

Row 4: [ TextView (~2/3 of the screen) ] [ Button (~1/3 of the screen) ]

Row 5: [ TextView (~2/3 of the screen) ] [ Button (~1/3 of the screen) ]

.....

:それは次のようになります。

これを行う方法は混乱しています。 TableLayoutまたはRelativeLayoutsでそれを行うことはできますか?私はXMLの使い方が分からないので、サンプルコードを誰かに見せてもらえますか?あなたのお手伝いをしてくれてありがとう!

答えて

1

はいあなたはLinearLayout - android:weightSumで、ここ

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

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="0.1" > 

     <TextView 
      android:text="left" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.33" /> 

     <Button 
      android:text="right" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.67" /> 

    </LinearLayout> 


EDIT、1行分の一例であることを行うことができます。私はあなたがそれを使用する方法を理解していなかったことがわかり 、 2つのレイアウト(main.xmlとlist_template.xml)があるとします。

main.xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ScrollView01" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 


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

    </LinearLayout> 
</ScrollView> 

list_template.xml

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

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="100" > 

     <TextView 
      android:text="left" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="33" 
      android:id="@+id/list_textView" /> 

     <Button 
      android:text="right" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="67" 
      android:id="@+id/list_button" /> 

    </LinearLayout> 

list_templateがリストの1行分のレイアウトテンプレートで、我々はそれを膨らませます。どうやって?

+1

これを明確にするために、これはListViewの行レイアウトになります。 – Brandon

+0

ごめんなさいListViewが何であるか分かりません。 1つのListView全体で複数のLinearLayoutsを持つことになりますか? – lordmarinara

+0

@ordmarinara私は使用法の詳細については私の答えを更新しました。 – ocanal

関連する問題