在此处输入图像描述我想创建类似于我们的手机主屏幕布局的东西,其中有许多应用程序的名称(包括图像按钮下方的文本(。我该怎么做?我不希望图像后面的灰色背景。有什么方法可以删除它吗?
我尝试使用GridView
但我不太喜欢按钮周围的大框,因为我正在尝试使用Imagebutton
。我也不能将layout_weight
与GridView
一起使用.
这是我所拥有的:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageButton
android:id="@+id/gallery_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/Attach_Gallery"
android:layout_weight="1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""/>
<ImageButton
android:id="@+id/Camera_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/Attach_Camera"
android:layout_weight="1"/>
<ImageButton
android:id="@+id/"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/Attach_Gallery"
android:layout_weight="1"/>
<ImageButton
android:id="@+id/gallery_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/Attach_Gallery"
android:layout_weight="1"/>
</LinearLayout>
我希望文本可以位于每个图像按钮下方,我还想要一个带有图像按钮和文本的 2x4 图表。
您还可以在主屏幕上添加回收器视图 布局 XML,并带有回收商视图,您还必须将回收器视图依赖项添加到应用程序级别的build.gradle文件中如
implementation 'com.android.support:recyclerview-v7:28.0.0'
您可以创建简单列表视图、交错布局以及网格布局。
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchMode="columnWidth"
android:numColumns="3"/>
之后,您必须为回收商视图创建一个自定义适配器。
RecyclerView.LayoutManager layoutManager1 = new GridLayoutManager(getContext(), 3);
rvSummary.setLayoutManager(layoutManager1);
rvSummary.setAdapter(alarmSummaryAdapter);