【发布时间】:2016-09-22 15:59:19
【问题描述】:
我正在制作一个可绘制的图层列表... 我想设置描边(2dp,颜色:#000000)、角(5dp)、背景(黄色)并在右侧添加图像,但我无法更改图像大小。
但我有类似的东西:
这是我的代码: content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="info.e_konkursy.myapplication.MainActivity"
tools:showIn="@layout/app_bar_main">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="200dp"
android:layout_height="20dp"
android:background="@drawable/bg_tablerow11"
android:padding="10dp">
<TextView
android:id="@+id/textView2"
android:layout_width="100dp"
android:text="@string/country"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="150dp"
android:layout_height="20dp"
android:text="Poland"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
</RelativeLayout>
bg_tablerow11.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:layout_width="10dp"
android:layout_height="10dp"
android:drawable="@drawable/arrow"
android:gravity="right" />
<item>
<shape
android:padding="10dp"
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#000000" />
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
</shape>
</item>
</layer-list>
感谢您的帮助。
【问题讨论】:
-
我可以看到您将相同的 xml 复制了两次。 “bg_tablerow11.xml”与“content_main.xml”相同
-
很抱歉,我的失误,现在没事了。
-
国名可以更改。默认是仅查看文本“国家:”和背景中的图像。我实现了 setOnClickListener 然后添加了国家/地区名称
-
为什么不在表格布局中放一个 imageview 呢?然后将没有图像的背景边框添加到相对布局中
-
哦,是的。感谢您的帮助
标签: android xml android-drawable