当前位置: 首页 > 知识库问答 >
问题:

在网格视图中具有文本叠加的图像布局,显示填充图像

宁浩博
2023-03-14

请帮我做这件事。我已经尝试了很多东西,甚至这里的反应如何显示图像上的文本,但没有得到所需的输出,如该页面的第一个图像所示。我试图用文本覆盖显示图像。我得到了一个用惰性适配器加载图像的代码。但是显示的图像在两侧都被填充。这是我得到的

这是我的代码:

平铺布局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;
}

共有1个答案

傅砚
2023-03-14

图像是否小于网格磁贴?如果需要扩展它们,请使用以下选项之一

 类似资料:
  • 好吧,我有gridview,它从服务器中提取图像

  • 问题内容: 我有一个包含图像和视频路径列表的数据库。我的问题是我必须将所有图像和视频显示在。我已经从数据库获取了路径列表,但无法在GridView中显示它们。请帮我。这是我的代码。提前致谢 问题答案: 是.. 经过长时间的实验,我得到了答案:这是: 这对我来说很好

  • 是否有任何方法可以使用android: fillViewport="true"和一个子LinearLayout填充所有视图,当LinearLayout的内容不够高时? 到目前为止,在ScrollView中的LinearLayout中,我们必须使用Android:layout _ height = " wrap _ content "。我们可以添加一些东西来填充所有的滚动视图吗?

  • android studio中的图像视图以xml布局显示,但在运行后的应用程序中没有显示。我尝试了所有可用的解决方案,但没有找到解决问题的方法。 我正在制作一个简单的meme共享应用程序,其中有两个按钮“共享”和“下一个”,单击“下一个”按钮后,出现了另一个meme。我使用了一个随机的meme api。我没有完成应用程序(没有为“下一个”按钮和“共享”按钮添加功能),只是为了检查是否显示了meme

  • 它将我带到图库以选择图像,但未显示在应用程序中,当单击上传按钮时,它只是一个空白图像视图 < li >我的Java代码 < li>XML代码 运行时显示此错误 java.lang.IllegalArgumentException:uri不能为空 以下两处给出错误的行显示了uri错误

  • 英文原文:http://emberjs.com/guides/views/adding-layouts-to-views/ 视图可以拥有一个次模板来包裹其主模板。如同模板一样,布局是可以插入到视图标签下的Handlebars模板。 通过设置layoutName属性来配置视图的布局模板。 而布局模板通过Handlebars的{{yield}}助手来指定在哪里插入主模板。视图渲染后的template的