8

レイアウト xml ファイルがあります。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
     android:id="@+id/titlename"  
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:text="@string/HostName"
 android:layout_weight="0"

/>
<TextView
     android:id="@+id/name"  
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
 android:layout_weight="0"
/>
</LinearLayout>

上記を実行すると、出力は次のようになります。

ここに画像の説明を入力

しかし、私の要件は、以下の出力を取得することです。

|   text1:    text2    |

誰でも助けることができますか?

4

9 に答える 9

27

次のコードを使用

ここに画像の説明を入力

更新日:

 <?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="fill_parent"
   android:orientation="horizontal"
   android:weightSum="1" >
<TextView
    android:id="@+id/titlename"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:gravity="center"
    android:text="hi" />
<TextView
    android:id="@+id/name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:gravity="center"
    android:text="2hi2" />
 </LinearLayout>
于 2013-04-23T18:09:57.847 に答える
0

実際、元のコードは私の ADT で完全に機能します。2 番目のテキストビューを更新する Java コードのテキスト サイズまたは行パディングを変更しましたか?

于 2013-04-23T18:26:34.957 に答える
0

属性を取り出しweightます。私が見ることができるのは、それが台無しになる唯一のことです。また、fill_parent非推奨であり、match_parent代わりに使用する必要があることに注意してください

または、何らかの理由で必要な場合は、weightそれぞれが画面の半分を占めるようにする場合は、 each を 1 に変更します。

また、使用weightする場合は設定する必要がありますandroid:layout_width="0dp"

于 2013-04-23T18:10:51.153 に答える
0

android:orientation="horizontal"LinearLayout を設定します。

于 2013-04-23T18:11:39.977 に答える