在textview中添加多个图像

时间:2016-12-15 09:48:04

标签: android image textview icons

enter image description here

我想制作类似上面的图像,但我没能实现!

add_expenses

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

    <TextView
        android:layout_width="320dp"
        android:layout_height="50dp"
        android:layout_marginTop="20dp"
        android:text="Receipt"
        android:drawableTint="@color/blue"
        android:drawablePadding="15dp"
        android:paddingTop="18dp"
        android:paddingLeft="15dp"
        android:drawableLeft="@drawable/receipt"
        android:drawableRight="@drawable/arrow"
        android:layout_marginLeft="10dp"
        android:textSize="23sp"
        android:textColor="@color/black"
        android:id="@+id/NoData"
        android:background="@drawable/roundedcorner_textview" />

</RelativeLayout>

roundedcorner_textview

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:width="3dp"
        android:color="@color/light_purple"/>
    <corners android:radius="3dp"/>

</shape>

我的输出

enter image description here

  1. 如何扩大形象?
  2. 我想箭头的颜色是黑色,而不是蓝色。
  3. 实现这一目标的最佳方法是什么?

6 个答案:

答案 0 :(得分:1)

尝试添加此代码

  <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:orientation="horizontal"
                android:background="@drawable/roundedcorner_textview"
                android:weightSum="1">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="0.9"
                    android:scaleType="centerInside"
                    android:tint="@color/colorPrimary"
                    android:src="@drawable/ic_receipt_white" />

                <LinearLayout
                    android:id="@+id/li_about"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="0.1"
                    android:orientation="horizontal"
                    android:paddingLeft="@dimen/activity_vertical_margin"
                    android:paddingTop="5dp"
                    android:weightSum="1">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="0.1"
                        android:text="Receipt"
                        android:textSize="17sp" />

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="0.9"
                        android:src="@drawable/forwardbutton"
                        />
                </LinearLayout>
            </LinearLayout>

答案 1 :(得分:1)

----------------- add_expenses.xml -------------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center">

    <LinearLayout
        android:layout_width="320dp"
        android:layout_height="50dp"
        android:background="@drawable/rounded_corner_textview"
        android:layout_gravity="center_vertical">



        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textColor="@android:color/black"
            android:textSize="38sp"
            android:text="Receipt"
            android:drawableLeft="@drawable/recepit"
            android:drawableRight="@drawable/forward_arrow"
            android:drawablePadding="10dp"  />

    </LinearLayout>

</LinearLayout>

---------------- rounded_corner_textview.xml ------------------

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:width="3dp"
        android:color="@android:color/black"/>
    <corners android:radius="3dp"/>

</shape>

------------------ forward_arrow.xml --------------------------

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/forward_arrow"
    android:tint="@android:color/black"
    />

------------------recepit.xml--------------------------

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/recepit"
    android:tint="@color/blue"
    />

答案 2 :(得分:0)

  <!--  You Can This View Achieve like this -->

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >

      <LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/roundedcorner_textview"
          >
        <TextView
            android:id="@+id/NoData"
            android:layout_width="320dp"
            android:layout_height="50dp"
            android:gravity="center_vertical"
            android:layout_marginLeft="10dp"
            android:drawablePadding="15dp"
            android:drawableLeft="@drawable/receipt"
            android:drawableRight="@drawable/arrow"
            android:drawableTint="@color/blue"
            android:text="Receipt"
            android:textColor="@color/black"
            android:textSize="23sp"
            />
      </LinearLayout>
    </RelativeLayout>

答案 3 :(得分:0)

为什么要使用TextView?

使用imageview

首先将relativeLayout置于圆角textview

之后
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/roundedcorner_textview">


     <ImageView 

      //set its src to blue page image
        />
<TextView

    android:textSize="23sp"
    android:textColor="@color/black"
    android:id="@+id/NoData"
    android:background="@drawable/roundedcorner_textview" 

       //keep this to right of above image view
      />

 <ImageView 

      //set its src to right arrow
    //and layoutalignParentright="true"
        />

 </RelativeLayout>

粗略的布局图

答案 4 :(得分:0)

更改可绘制xml中的内容以减少或增加图像的大小

android:width="24dp"
android:height="24dp"

更改颜色,更改xml文件中的颜色

答案 5 :(得分:-1)

1.如何扩大图像?

答。如果你想增加图像大小,那么增加textview的高度或使用gravity属性将你的两个图像居中。

2.我希望箭头的颜色是黑色,而不是蓝色。

答。如果你想要黑色arrot而不是蓝色,那么用黑色箭头drawble图像替换那个蓝色的drawble图像。