【问题标题】:Multiple ListView and buttons widht多个 ListView 和按钮宽度
【发布时间】:2016-10-29 16:07:56
【问题描述】:

我正在尝试为 Android 应用程序执行 this layout,但我不断得到不同的结果。我的第一个问题是我只能看到第一个 ListView,而第二个总是隐藏的。第二个是我想创建 3 个具有“标签样式”的按钮。我尝试使用

android:layout_weight= "0.33"

对于按钮,但我仍然无法获得该结果。 这是我目前的布局:

<?xml version="1.0" encoding="utf-8"?>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Start"
    android:id="@+id/button"
    android:layout_weight=".33"
    android:layout_alignTop="@+id/buttonP"
    android:layout_centerHorizontal="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Previous"
    android:id="@+id/buttonP"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_weight= "0.33"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Next"
    android:id="@+id/buttonN"
    android:layout_above="@+id/custom_list"
    android:layout_alignRight="@+id/custom_list"
    android:layout_alignEnd="@+id/custom_list"
    android:layout_weight= "0.33"/>

<ListView
    android:layout_below="@+id/button"
    android:id="@+id/custom_list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="1dp"
    android:layout_weight="0.5"/>

<ListView
    android:layout_below="@+id/custom_list"
    android:id="@+id/custom_list_2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="1dp" />

这是列表元素的布局

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:typeface="sans" />

<TextView
    android:id="@+id/price"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/title"
    android:layout_marginTop="5dip"
    android:textColor="#343434"
    android:textSize="12sp" />

<TextView
    android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/price"
    android:layout_alignBottom="@+id/price"
    android:layout_alignParentRight="true"
    android:textColor="#343434"
    android:textSize="12sp" />

【问题讨论】:

  • 你目前的结果是什么?
  • 这个布局。 imgur.com/n9KelCt
  • 有一个选项可以使用 ExpandableListview... 它会根据点击展开您的列表,就像菜单栏中的那个。但是你可以使用 nestedRecyclerView ,它实际上解决了 ListView 的许多缺点......

标签: android xml android-layout listview button


【解决方案1】:

您应该尝试使用此百分比支持库来完成您的布局: https://developer.android.com/topic/libraries/support-library/features.html#percent

当您需要根据百分比宽度和高度创建布局时,它非常有用。 网上有很好的教程教你如何有效地使用它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多