4

私は次のようにレイアウトを設計しています

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

    <TextView
        android:id="@+id/messageText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Some really long text asd asd asd asd asd asd asd asd asd asd asd" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="12:45 PM" />

</LinearLayout>

上記のようなUIを提供します...

長いテキスト画像

これは私が必要とする完璧なものです。向きが水平であるため、Button を画面から離すことなく、長いテキストが適切に折り返されます。ボタンも伸びません。

ただし、テキストが小さい場合。このように見えます

短いテキスト画像

私が欲しいのは、このようにボタンをテキストの左端に揃える必要があることです

短い正しいテキスト

レイアウトの重みを1にするとわかります。

ボタンに必要なスペースを与えた後に残った領域全体を消費します。

それを入れないと。幅を折り返しコンテンツにします。短いテキストに最適です。しかし、テキストが大きくなるにつれて。

ボタンを押して画面から離します。

それが問題です。問題を十分に説明できることを願っています。しかし、もちろん読むのは長いです。もちろん痛い。しかし、ポインタを知って本当にうれしいです。

相対レイアウトも使用することに消極的ではありません。

どんな助けでも大歓迎です。

ありがとう

4

3 に答える 3

7

これがうまくいくことを願っています。これを試してください:

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

<TextView
    android:id="@+id/messageText"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="Some really long text asd asd asd asd asd asd asd asd asd asd asd![enter image description here][1]" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="12:45 PM" />

linearlayout のandroid:layout_width="fill_parent"android:layout_width ="wrap_content"に変更する必要があると思います

于 2013-04-05T13:10:31.440 に答える
1

これを試して:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
    android:id="@+id/messageText"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
     android:layout_weight="1.0"
    android:text="Some really long text asd asd asd asd asd asd asd asd asd asd asd![enter image description here][1]" />

<Button
    android:id="@+id/button1"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:text="12:45 PM" />

于 2013-04-05T13:10:41.670 に答える
0

私は自分のデバイスでそれをテストし、正常に動作しました。それを試してみてください

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

<TextView
    android:id="@+id/messageText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="sdgdsgdhdhdfhdhgfffffffffffffffffffffffffffffffffffffffff" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="12:45 PM" />

</LinearLayout>
于 2013-04-05T13:34:57.520 に答える