我想让我的列表项看起来像这样 -
我有一个项目列表,这些项目具有与之关联的 % 值。这个布局看起来真的很吸引人。谁能告诉我如何做到这一点?
这是我试过的代码 -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:orientation="horizontal"
android:background="#98F5FF"
android:layout_height="wrap_content"
>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/text1"
android:textSize="25dip"
android:textColor="#FFFFFF"
android:text="This is text1"/>
</LinearLayout>
</RelativeLayout>
最佳答案
您可以使用相对布局,线性布局用于绿色背景,另一种布局用于放置所有项目,这样背景就不会覆盖它们。根据百分比更改背景线性布局的宽度。 这是您的 xml 的示 Intent :
<RelativeLayout>
<LinearLayout /> // for background
<LinearLayout android:background="@android:color/transparent">
//all other elements in your view go here
</LinearLayout>
</RelativeLayout>
通过myLinearLayout.getLayoutParams().height = x;设置线性布局的高度
关于android - 如何在 ListView 中拥有高级列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7430684/