请帮我解决这个问题。 我已经尝试了很多东西,甚至是How to show Text on Image的响应,但没有获得所需的输出,如该页面的第一张图片所示。 我正在尝试使用文本叠加显示图像。我有一个代码用Lazy Adapter加载图像。 但是显示的图像在两侧都有填充。 这是我得到的
以下是我的代码:
tile layout xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/tileimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/logo"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<TextView
android:id="@+id/tilecontent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold"
android:background="#55000000" />
</LinearLayout>
</RelativeLayout>
网格布局
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:stretchMode="columnWidth"
android:numColumns="2"
/>
</FrameLayout>
我从这里给瓦片充气
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private String[] content;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity act, String[] cont) {
activity = act;
content = cont;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return content.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if(convertView == null)
view = inflater.inflate(R.layout.hometile, parent, false);
view.setId(position);
TextView text=(TextView)vi.findViewById(R.id.tilecontent);;
ImageView image=(ImageView)vi.findViewById(R.id.tileimage);
if(position == 0)
{
text.setText("One");
}
else if(position == 1)
{
text.setText("Two");
}
else if(position == 2)
{
text.setText("Three");
}
else if(position == 3)
{
text.setText("Four");
}
else if(position == 4)
{
text.setText("Five");
}
else if(position == 5)
{
text.setText("Six");
}
imageLoader.DisplayImage(data[position], image);
return view;
}