我面临一个奇怪的问题。我有一个AdapterViewFlipper小部件,显示不完整的TextViews。例如,我有一串文本声明为 -
String fruitNames[] = {"Apple", "Pine Apple", "Litchi", "Mango", "Banana"};
现在的问题是,它的显示
“Pine Apple”为“Pine”而不是Pine Apple ..空格后的文字被省略。
有时候,“荔枝”会以“Litc”和Banana的形式显示为“Bana”
我的惯例是
public class CustomAdapter extends BaseAdapter {
Context context;
int[] fruitImages;
String[] fruitNames;
LayoutInflater inflter;
public CustomAdapter(Context applicationContext, String[] fruitNames, int[] fruitImages) {
this.context = applicationContext;
this.fruitImages = fruitImages;
this.fruitNames = fruitNames;
inflter = (LayoutInflater.from(applicationContext));
}
@Override
public int getCount() {
return fruitNames.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
view = inflter.inflate(R.layout.list_item, null);
TextView fruitName = (TextView) view.findViewById(R.id.fruitName);
ImageView fruitImage = (ImageView) view.findViewById(R.id.fruitImage);
fruitName.setText(fruitNames[position]);
fruitImage.setImageResource(fruitImages[position]);
return view;
}
}
在mainacitvity中 -
simpleAdapterViewFlipper = (AdapterViewFlipper) findViewById(R.id.simpleAdapterViewFlipper;
CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), fruitNames, fruitImages);
simpleAdapterViewFlipper.setAdapter(customAdapter);
simpleAdapterViewFlipper.setFlipInterval(3000);
simpleAdapterViewFlipper.setAutoStart(true);
}
}
我真的无法解决问题。我尝试将Textview高度设置为行xml的匹配父级,但仍显示部分文本。 请帮我解决一下。
<?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"
android:background="#fff"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/fruitImage"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_gravity="center" />
<TextView
android:id="@+id/fruitName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:textColor="#000" />
</LinearLayout>
这是行布局