android-fragments 如何在Android中设计这种类型的边框

w6lpcovy  于 2022-11-13  发布在  Android
关注(0)|答案(3)|浏览(148)

我是新的Android应用程序。我想设计这种类型的边框。
其设计为:

并告诉我我应该使用哪个布局和视图(网格视图,相对或线性)。也帮助我选择任何框的颜色应该改变。

falq053o

falq053o1#

您可以使用GridView执行此操作

<GridView
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="2"
         android:background="@drawable/selector" >
    </GridView>

android:numColumns设置为所需的数字。并将选择器作为背景添加到GridView中

js4nwp54

js4nwp542#

这看起来像是GridView
对于这种类型的边框,您需要一种形状:
您需要在drawable文件夹中创建2个形状和一个选择器:
1)正常状态(未按下)
2)为您的紧迫状态
3)将用作gridItem背景的最终形状
1)网格项目形状

/*This will looke like your border without the textview 
  (you can make the textview color blue from your adapter or your layout file) */

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid android:color="@color/grid_view_color"/>
    <stroke android:width="1dp" android:color="#001414"/>
</shape>

2)网格项目形状已按下

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid android:color="#ffc392"/>
    <stroke android:width="2dp" android:color="#001414"/> //choose your own color here
</shape>

3)网格_项目_背景

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/grid_item_shape"
    android:state_pressed="false">
</item>
    <item android:drawable="@drawable/grid_item_shape_pressed"
        android:state_pressed="true">
    </item>
</selector>
kyvafyod

kyvafyod3#

如果块(框)的大小可变,则可以选择GridView
其他
选择嵌套在LinearLayout中的一些视图(TextView或Button)
对于选择颜色,您可以添加一个选择器drawable文件夹,请参考Selector Example

相关问题