android - 如何在 ListView 中拥有高级列表项

标签 android listview

我想让我的列表项看起来像这样 -

enter image description here

我有一个项目列表,这些项目具有与之关联的 % 值。这个布局看起来真的很吸引人。谁能告诉我如何做到这一点?

这是我试过的代码 -

<?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/

相关文章:

java - 如何在 SharedPreferences 中保存 JSON 数组?

java - 使用 GSON 将 JSON 转换为 Java 对象时如何覆盖 Java 映射?

c# - 在C#中的 ListView 中从access数据库获取数据

android - 有没有办法在android任务切换器中更改应用程序的缩略图(长按主页按钮)

android - 在设置中更改背景颜色

android - 如果手机( native )中存在多条未读短信,如何通知从 native (手机)读取了哪些短信?

java - listView 不会从底部填充

android - 在自定义 ListView android中获取JSON结果

android - 更改 ListView 项的文本颜色时出现 NullPointerException

java - View 未正确包含在单个列表项中