在GridLayout中按钮不会显示或删除 [英] buttons don't show up or remove each other in GridLayout
问题描述
以下是我的问题:当某些图片放入GridLayout时,周围的其他应用图片会消失。我注意到图像似乎推出了其他图像从视图中有非常大的图像
Here is my problem: When some of the images get placed in the GridLayout the other app images around them disappear. I've noticed that the image that seem to "push out" the other images from the view have really big IMAGES
推荐答案
我将概述XML中可能导致一些问题的一些方面。首先,您需要一个XML布局文件,
看起来像下面那样将保留您的顶级布局。这将在它自己的文件中。
I will outline some areas in the XML that may be causing you some problems. First, you need an XML layout file that looks something like the following that will hold your top-level layout. This will be in its own file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
请注意,RecyclerView在LinearLayout中是独立的。接下来需要一个单独的XML文件
,它将为布局的每个单元格保存ImageButton和TextView的布局。这将适合您的RecyclerView中网格的每个
单元格。我使用 android:scaleType =centerCrop
将大图像放入ImageButton。
Notice that the RecyclerView stands alone within the LinearLayout. You will next need a separate XML file
that will hold the layout for the ImageButton and TextView for each cell of your layout. This will fit into each
cell of the grid in your RecyclerView. I used android:scaleType="centerCrop"
to fit large images into the ImageButton.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<ImageButton
android:id="@+id/new_app_button"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/new_app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/new_app_button"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
</RelativeLayout>
onCreateViewHolder()
of RecyclerViewHolder
将如下所示,假设grid_cell.xml是上述XML文件的名称
。
onCreateViewHolder()
of RecyclerViewHolder
will look like the following assuming "grid_cell.xml" is the name
of the XML file above.
@Override
public RecyclerViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.grid_cell, parent, false);
RecyclerViewHolders holder = new RecyclerViewHolders(layoutView);
return holder;
}
试一试。我认为其他一切都还可以。我希望它可以帮到你。
Give this a try. I think that everything else is OK. I hope it helps you.
这篇关于在GridLayout中按钮不会显示或删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!