Android 在textview中添加多个图像
我想做一些像上面的图片,但我没能做到 添加费用Android 在textview中添加多个图像,android,image,textview,icons,Android,Image,Textview,Icons,我想做一些像上面的图片,但我没能做到 添加费用 <?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"
<?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>
圆角_文本视图
<?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>
我的输出
实现这一目标的最佳方法是什么。如何将图像放大? 答:如果要增加图像大小,请增加文本视图的高度,或使用
重力
属性将两幅图像居中
2。我希望箭头的颜色是黑色,而不是蓝色。
答:如果您想要黑色箭头而不是蓝色,请将蓝色可绘制图像替换为黑色箭头可绘制图像。尝试添加此代码
<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>
不要使用文本视图。使用imageview 首先将relativeLayout的背景保留为圆角文本视图:
<?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 the blue page image -->
/>
<TextView
android:textSize="23sp"
android:textColor="@color/black"
android:id="@+id/NoData"
android:background="@drawable/roundedcorner_textview"
<!-- Keep this to the right of the above image view -->
/>
<ImageView
<!-- Set its src to the right arrow
and layoutalignParentright="true".
-->
/>
</RelativeLayout>
/>
在可绘制XML中更改以下内容以减小或增大图像的大小:
android:width="24dp"
android:height="24dp"
要更改颜色,请更改XML文件中的颜色。-------------------add\u expenses.XML-------------------
----------------- 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"
/>
----------------圆角_corner_textview.xml------------------
------------------前进箭头.xml--------------------------
------------------recepit.xml--------------------------
使用带填充的可绘制黑色图像。并删除paddingTop属性请检查图像维度。图像的角点应等间距排列。另外,请尝试textview活动中心垂直。也许这能解决你的问题。并删除文本视图中的顶部填充
----------------- 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"
/>