android如何在后台xml中更改大小图像

时间:2016-09-22 15:59:19

标签: android xml android-drawable

我为drawable制作了一个图层列表... 我想设置笔画(2dp,颜色:#000000),角落(5dp),背景(黄色)并在右侧添加图像,但我无法改变图像尺寸。

我想要的: What i want

但我有类似的东西:

wrong effect

这是我的代码: 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>

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

A.J。谢谢你的帮助:)

答案: content_main.xml:

  

<RelativeLayout
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@drawable/bg_tablerow">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="100dp"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="@string/country"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="150dp"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_marginEnd="22dp"
        android:layout_marginRight="22dp"
        android:layout_toLeftOf="@+id/imageView2"
        android:layout_toStartOf="@+id/imageView2"
        android:gravity="center_vertical"
        android:text="Poland"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginEnd="19dp"
        android:layout_marginRight="19dp"
        android:background="@drawable/arrow"
        android:scaleType="fitXY" />

</RelativeLayout>
     

bg_tablerow.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FFEE00" />
            <corners
                android:bottomLeftRadius="10dp"
                android:bottomRightRadius="10dp"
                android:topLeftRadius="10dp"
                android:topRightRadius="10dp" />
            <stroke
                android:width="5dp"
                android:color="#eeaaff" />
        </shape>
    </item>
</layer-list>