Android TextView's stopped wrapping text

2019-02-27 08:48发布

问题:

I spent a ton of time looking for a solution to this but have not found anything that seems similar to what I am experiencing. When I run my app on my G2 none of my textviews wrap text.(regardless of how large the views are.) If i run it on an emulator they wrap appropriately. None of my other apps seem to have this problem when deployed to my G2. I have power cycled my devices, recreated layouts, etc. This seems to even affect a standard alert dialog in this particular app. It is happening in all my activities. Has anyone seen anything like this or does anyone have an idea what I should be looking at?

Some code as requested...

AlertDialog.Builder eula = new AlertDialog.Builder(activity)
            .setTitle(R.string.eula_title)
            .setIcon(android.R.drawable.ic_dialog_info)
            .setMessage(R.string.eula_text)
            .setCancelable(accepted)
            .setPositiveButton(R.string.eula_accept,
                        new android.content.DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                setAcceptedEula(activity);
                                dialog.dismiss();
                                mHandler.post(mSplashScreen.launch);
                            }
                        })
            .setNegativeButton(R.string.eula_decline,
                        new android.content.DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                                activity.finish();
                            }
                        });
    eula.show();

Standard alert dialog won't wrap text. It shows one line that trails off the view.

回答1:

OK so i figured it out.
I have a theme applied to my app with parent theme Theme.Holo.

When I removed that theme as the parent my textviews started wrapping again! I don't know why other then when run on a device that doesn't understand Theme.Holo it got confused.

So I just created an additional values-v13 directory and modified my themes. Sorry for the trouble folks.



回答2:

In addition to Larry McKenzie answer I had to set corresponding parameters to the TextView:

android:ellipsize="none"
android:maxLines="20"
android:scrollHorizontally="false"
android:singleLine="false" 

Example:

<TextView                  
  android:textColor="@color/white"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:ellipsize="none"
  android:maxLines="20"
  android:scrollHorizontally="false"
  android:singleLine="false"
  android:text="@string/my_text" />