我一直在尝试使用TextView将文本包装到Android 2.3.3上的多行中一段时间但是我无法接通以使其工作,即使在最基本的级别上也是如此。无论我做什么,文本总是只是切断屏幕的边缘。它在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>
答案 0 :(得分:3)
我遇到了同样的问题。我只想说我刚刚使用Android 2.3.3平台更改为Android 4.0.3平台,因为我想利用Holo主题。所以我的默认主题看起来像这样。
<style name="mytheme" parent="android:Theme.Holo">
<item name="android:windowNoTitle">true</item>
</style>
我的所有textViews在运行Android 4.0.3的手机上看起来都很棒
但是当我在运行Android 2.3.3的模拟器中运行我的应用程序时,没有任何textViews包装。我用谷歌搜索和谷歌搜索,几乎尝试了每一个组合:
android:inputType="textMultiLine"
android:scrollHorizontally="false"
android:ellipsize="none"
android:layout_weight="1"
纳达。所以我决定恢复原来的主题:
<style name="myapp" parent="android:Theme.Black.NoTitleBar"/>
中提琴! TextViews再次开始包装。去搞清楚。不是一个真正的解决方案,但也许其他人可以解释为什么。
答案 1 :(得分:1)
这是一个很好的相关答案,表明您可以根据其运行的Android 版本使用不同的主题 - 只需创建一个版本化的样式文件夹。
答案 2 :(得分:0)
我遇到了类似Android 2.3和4.x的问题。正如@Richard Le Mesurier在回答这个问题时引用的那样,问题与主题有关:Android 4.x使用Holo主题,它不会打破长线。 Richard所引用的解决方案是通过使用版本化样式实现的。
但是我通过向EditText添加两个属性而没有使用版本化样式解决了这个问题:android:scrollHorizontally =“false”和android:inputType =“textMultiLine”。问题是通过将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" />