3

Android 2.3.3 でテキストを複数行に折り返すように TextView を取得しようとしていましたが、最も基本的なレベルであっても機能させることができません。何をしても、テキストは常に画面の端で途切れます。Android 4 でも問題なく動作しますが、2.3.3 もターゲットにしたいと考えています。

ここで基本的な部分だけを試しました:

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

    <TextView
                android:id="@+id/mainDescText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/A_MORE_DESCRIPTION_TEXT" />
</LinearLayout>

しかし、それでもテキストはラップされません。これを機能させようとしている私の実際のレイアウトは次のとおりです。

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

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

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

            <TextView
                android:id="@+id/mainDescText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:lines="2"
                android:text="@string/A_MORE_DESCRIPTION_TEXT" />
        </RelativeLayout>

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

            <TextView
                android:id="@+id/ageCurrentText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/ageButton"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:text="@string/A_MORE_CURRENT_SIGHTINGS_AGE" />

            <Button
                android:id="@+id/ageButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:onClick="loadSightingsAge"
                android:text="@string/A_MORE_SIGHTINGS_AGE_BUTTON" />
        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="80dp"
            android:layout_marginTop="10dp" >

            <TextView
                android:id="@+id/languageCurrentText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/languageButton"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:text="@string/A_MORE_CURRENT_LANGUAGE" />

            <Button
                android:id="@+id/languageButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:onClick="loadLanguage"
                android:text="@string/A_MORE_LANGUAGE_BUTTON" />
        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="10dp" >

            <ImageView
                android:id="@+id/redPinImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/red_pin"
                android:contentDescription="@string/A_MORE_RED_PIN_IMAGE" />

            <TextView
                android:id="@+id/redPinText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/redPinImage"
                android:text="@string/A_MORE_RED_PIN_DESCRIPTION" />

        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="10dp" >

            <ImageView
                android:id="@+id/yellowPinImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/yellow_pin"
                android:contentDescription="@string/A_MORE_YELLOW_PIN_IMAGE" />

            <TextView
                android:id="@+id/yellowPinText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/yellowPinImage"
                android:text="@string/A_MORE_YELLOW_PIN_DESCRIPTION" />

        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="10dp" >

            <ImageView
                android:id="@+id/greenPinImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/green_pin"
                android:contentDescription="@string/A_MORE_GREEN_PIN_IMAGE" />

            <TextView
                android:id="@+id/greenPinText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/greenPinImage"
                android:text="@string/A_MORE_GREEN_PIN_DESCRIPTION" />

        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="10dp" >


            <TextView
                android:id="@+id/thanksText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="@string/A_MORE_CREATED_BY_TEXT" />

        </RelativeLayout>

    </LinearLayout>
</ScrollView>

編集: 何を変更したか正確には思い出せませんが、このxmlで動作させることができました:

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

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

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

            <TextView
                android:id="@+id/mainDescText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:lines="3"
                android:scrollHorizontally="false"
                android:text="@string/A_MORE_DESCRIPTION_TEXT" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/ageCurrentText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/ageButton"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:gravity="center"
                android:text="@string/A_MORE_CURRENT_SIGHTINGS_AGE" />

            <Button
                android:id="@+id/ageButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:onClick="loadSightingsAge"
                android:text="@string/A_MORE_SIGHTINGS_AGE_BUTTON" />
        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="80dp"
            android:layout_marginTop="10dp" >

            <TextView
                android:id="@+id/languageCurrentText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/languageButton"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:gravity="center"
                android:text="@string/A_MORE_CURRENT_LANGUAGE" />

            <Button
                android:id="@+id/languageButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:onClick="loadLanguage"
                android:text="@string/A_MORE_LANGUAGE_BUTTON" />
        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="10dp" >

            <ImageView
                android:id="@+id/redPinImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/red_pin"
                android:contentDescription="@string/A_MORE_RED_PIN_IMAGE" />

            <TextView
                android:id="@+id/redPinText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/redPinImage"
                android:lines="3"
                android:scrollHorizontally="false"
                android:text="@string/A_MORE_RED_PIN_DESCRIPTION" />

        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="10dp" >

            <ImageView
                android:id="@+id/yellowPinImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/yellow_pin"
                android:contentDescription="@string/A_MORE_YELLOW_PIN_IMAGE" />

            <TextView
                android:id="@+id/yellowPinText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/yellowPinImage"
                android:lines="3"
                android:scrollHorizontally="false"
                android:text="@string/A_MORE_YELLOW_PIN_DESCRIPTION" />

        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="10dp" >

            <ImageView
                android:id="@+id/greenPinImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/green_pin"
                android:contentDescription="@string/A_MORE_GREEN_PIN_IMAGE" />

            <TextView
                android:id="@+id/greenPinText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/greenPinImage"
                android:lines="3"
                android:scrollHorizontally="false"
                android:text="@string/A_MORE_GREEN_PIN_DESCRIPTION" />

        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="10dp" >


            <TextView
                android:id="@+id/thanksText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:gravity="center"
                android:lines="3"
                android:scrollHorizontally="false"
                android:text="@string/A_MORE_CREATED_BY_TEXT" />

        </RelativeLayout>

    </LinearLayout>
</ScrollView>
4

3 に答える 3

3

私はまったく同じ問題を抱えていました。Holo テーマを利用したかったので、最近 Android 2.3.3 プラットフォームから Android 4.0.3 プラットフォームに変更したばかりです。したがって、私のデフォルトのテーマは次のようになりました。

<style name="mytheme" parent="android:Theme.Holo">
    <item name="android:windowNoTitle">true</item>
</style>

私のすべての textViews は、Android 4.0.3 を実行している携帯電話で見栄えがよくなりました

しかし、Android 2.3.3 を実行しているエミュレーターでアプリを実行すると、textView がラップされませんでした。私はググってググって、ほとんどすべての組み合わせを試しました:

  android:inputType="textMultiLine"
  android:scrollHorizontally="false"
  android:ellipsize="none"
  android:layout_weight="1"

なだ。そこで、元のテーマに戻すことにしました。

<style name="myapp" parent="android:Theme.Black.NoTitleBar"/>

ビオラ!TextViews が再びラッピングを開始しました。図に行きます。本当の解決策ではありませんが、他の誰かがその理由を明らかにすることができます.

于 2012-06-22T21:51:30.930 に答える
1

これは、実行中の Android のバージョンに応じて異なるテーマを使用できることを示す適切な関連回答です。バージョン管理されたスタイル フォルダーを作成するだけです。

ここで答えてください: TextView はテキストを分割しません

于 2012-12-10T09:30:41.997 に答える
0

Android 2.3 および 4.x に関しても同様の問題がありました。この質問への回答で @Richard Le Mesurier が引用したように、この問題はテーマに関連しています。Android 4.x は、長い行を分割しない Holo テーマを使用しています。Richard が引用した解決策は、バージョン管理されたスタイルを使用することによって実現されます。

しかし、EditText に android:scrollHorizo​​ntally="false" と android:inputType="textMultiLine" の 2 つのプロパティを追加することで、バージョン管理されたスタイルを使用せずに問題を解決しました。問題は、inputType を textMultiline として追加することです。スペル チェッカーは Android 4.x で有効になっています。そのため、inputType プロパティに「textNoSuggestions」を追加することで、スペルチェッカーが無効になり、問題が解決されます。

<TextView 
   android:id="@+id/my_text"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:scrollHorizontally="false"
   android:inputType="textMultiLine|textNoSuggestions"
   android:layout_marginTop="2dp"
   android:ellipsize="end" />
于 2013-02-25T19:12:57.593 に答える