[英]How to implement this kind of layout
This is the design effect . 这就是设计效果 。
I tried to use the LinearLayout
to implement it like this: 我试图使用
LinearLayout
像这样实现它:
<LinearLayout
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center">
<TextView
android:text="Type"
android:background="@drawable/poi_nearby_cell"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"/>
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1">
<TextView
android:text="Type1"
android:background="@drawable/poi_nearby_cell"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<TextView
android:text="Type2"
android:background="@drawable/poi_nearby_cell"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1">
<TextView
android:text="Type3"
android:background="@drawable/poi_nearby_cell"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<TextView
android:text="Type4"
android:background="@drawable/poi_nearby_cell"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
And the poi_nearby_cell
: 还有
poi_nearby_cell
:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@android:color/transparent">
</solid>
<stroke
android:width="0.5dp"
android:color="#A0A0A0">
</stroke>
</shape>
This is what I got now. 这就是我现在得到的。
However I meet many problems: 但是我遇到很多问题:
1 I use the drawable/poi_nearby_cell
to create the border for the textview. 1我使用
drawable/poi_nearby_cell
为textview创建边框。
However I have also to implement the cell press effect like the "Type1" in the design effect picture. 但是,我还必须在设计效果图片中实现像“ Type1”这样的单元格按效果。 Generally I set axml drawable resource as the background like this:
通常,我将axml drawable资源设置为这样的背景:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<color android:color="#ffebf6ff"/>
</item>
<item>
<color android:color="#fffefefe"/>
</item>
</selector>
However in my case, I cannot set a view with two background at the same time. 但是,就我而言,我无法同时设置两个背景的视图。 Any alternative?
还有其他选择吗?
2 As you can see, the border have different width value. 2如您所见,边框的宽度值不同。 Normally I want the border to be
1dp
however, in my example, the border between two cell maybe 2dp
. 通常,我希望边界为
1dp
但是在我的示例中,两个单元格之间的边界可能是2dp
。
I have no idea to continue. 我不知道要继续。 Any suggestions?
有什么建议么?
// try this
**layout_bg.xml**
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#333333" />
<corners android:radius="5dp" />
<stroke
android:width="1dp"
android:color="@android:color/darker_gray" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="5dp"
android:gravity="center">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@drawable/layout_bg"
android:padding="1dp">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:padding="1dp"
android:background="@android:color/darker_gray"
android:layout_weight="1">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
<TextView
android:text="Type"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:orientation="vertical"
android:layout_weight="1">
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:padding="1dp"
android:layout_width="match_parent"
android:background="@android:color/darker_gray"
android:orientation="vertical">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:background="@android:color/white">
<TextView
android:text="Type1"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:background="@android:color/darker_gray"
android:padding="1dp"
android:orientation="vertical">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:background="@android:color/white">
<TextView
android:text="Type2"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:orientation="vertical"
android:layout_weight="1">
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:padding="1dp"
android:layout_width="match_parent"
android:background="@android:color/darker_gray"
android:orientation="vertical">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:background="@android:color/white">
<TextView
android:text="Type3"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:background="@android:color/darker_gray"
android:padding="1dp"
android:orientation="vertical">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center"
android:background="@android:color/white">
<TextView
android:text="Type4"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.