【问题标题】:Boundry around a view视图周围的边界
【发布时间】:2016-03-02 09:53:30
【问题描述】:
我想要图像中显示的视图周围的边界:
https://projects.invisionapp.com/share/785LXW0SQ#/screens/137849056
我在 textview 上方布局的 xml 代码有文本“调用”:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:id="@+id/cardview0"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textColor="#3B64AE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Circle"
android:layout_marginLeft="30dp"
android:layout_gravity="center_vertical"
android:layout_centerVertical="true"
/>
<Spinner
android:layout_alignParentEnd="true"
android:layout_width="150dp"
android:layout_height="match_parent">
</Spinner>
</RelativeLayout>
</android.support.v7.widget.CardView>
假设我想要一个围绕这个卡片视图的边界。我该怎么做?
【问题讨论】:
标签:
android
android-layout
android-studio
android-view
【解决方案1】:
试试这个:
卡片视图内的边界线:
<android.support.v7.widget.CardView
android:id="@+id/cardview0"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:background="#000000">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0.5dp"
android:layout_marginLeft="0.5dp"
android:layout_marginTop="0.5dp"
android:background="#ffffff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="30dp"
android:text="Circle"
android:textColor="#3B64AE" />
<Spinner
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true">
</Spinner>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
cardview外的边界线:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:background="@drawable/border_line">
<android.support.v7.widget.CardView
android:id="@+id/cardview0"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="1dp"
android:layout_alignParentTop="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="30dp"
android:text="Circle"
android:textColor="#3B64AE" />
<Spinner
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true">
</Spinner>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
可绘制->border_line.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="000000" />
</shape>