enter image description here我正在开发一个Android应用程序。
我动态创建了名称(从服务器获得),但是现在我需要添加相同高度和宽度的彩色矩形,并在其中添加一些textview。
我已附上需要开发的图像。
我该如何实现?使用画布?我发现这很困难。
最佳答案
对于TextView,只需添加填充和背景即可实现:)
尝试这个:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#BBBBBB"
tools:context="xyz.mhuy.myapplication.MainActivity">
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/black" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HelloWorld"
android:padding="10dp"
android:textColor="#ffffff"
android:gravity=""/>
<TextView
android:id="@+id/button2"
android:padding="10dp"
android:background="#ff0000"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</LinearLayout>
上面是什么意思?结果是: