gpt4 book ai didi

android - 如何为布局设置边框

转载 作者:太空宇宙 更新时间:2023-11-03 11:52:32 26 4
gpt4 key购买 nike

我想为 Relativelayout 设置边框。我使 relativelayout 可点击并使用选择器来更改所选颜色,我还使用形状来圆角布局。但是当我选择布局时,形状会占据所有背景,包括边框。我找不到解决这个问题的方法。

这是我的 main.xml

<RelativeLayout android:id="@+id/map_refresh"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:background="@drawable/settings_selector_up"
android:padding="15dp"
android:layout_marginLeft="15dip" android:layout_marginRight="15dip" android:layout_marginTop="5dip">
<TextView android:id="@+id/Text1"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="Map refresh period">
</TextView>
<TextView android:id="@+id/TextView09"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="1 min"
android:layout_alignParentRight="true"
android:paddingRight="5dp">
</TextView>
</RelativeLayout>
</LinearLayout>

这是我的 settings_selector_up.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false"
android:state_pressed="false" android:background="@drawable/settings_border_roundup" />
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="false" android:drawable="@drawable/settings_border_roundup" />

<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false"
android:state_pressed="false" android:drawable="@drawable/settings_border_roundup" />
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@drawable/settings_border_roundup" />

<!-- Pressed -->
<item android:state_selected="true" android:state_pressed="true"
android:drawable="@drawable/selector_pressed" >
</item>
<item android:state_pressed="true" android:drawable="@drawable/list_selector_pressed" />
</selector>

这是我的 selector_pressed

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#E6E6E6"></solid>
<corners android:radius ="10dp" />
</shape>

有没有一种方法可以收到与我们在 listView 中使用 listselector 时相同的结果(在 listview 中,当我选择列表项时,只有背景颜色发生变化,但边框保持不变)。

最佳答案

将整个内容放在另一个处理边框绘制的父布局中,如下所示:

<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="your background 9-patch or shape of the border"
android:padding="some padding value so the border looks ok">

< Your RelativeLayout without the border stuff >

</FrameLayout>

关于android - 如何为布局设置边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8322029/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com