【问题标题】:Rounded button on the ListViewListView 上的圆形按钮
【发布时间】:2014-08-13 11:42:08
【问题描述】:

我有这样的布局

<ListView>
    andorid:layout_width="math_parent"
    android:layout_height="math_parent"
    android:orientation="vertical" >
    <ListView>
        andorid:layout_width="math_parent"
        android:layout_height="wrap_content"
        android:orientation="horisontal" >
        <TextView 
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:textColor="@android:color/black"
            android:layout_gravity="center_vertical"
            android:text="bla bla"
            android:textSize="13sp" />
        <ImageView 
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:background="@drawable/round_button"
            android:layout_weight="1" />
    </ListView>

    .........
</ListView>

所以我的圆形按钮不是圆形的,导致子布局中高度小于父主布局中的像素数。我怎样才能得到圆形按钮? 谢谢

【问题讨论】:

  • 如果你想在你的ListView 中有TextViewImageView,那么你应该扩展另一个布局,在那个布局中你应该有TextViewImageView。这不是这样做的方法。
  • 什么是round_button? XML?还是图片?
  • 我想你对ListView的概念感到困惑。你想要达到的是listview with custom rows
  • 为列表中的项目创建具有自定义布局的自定义列表视图。就像@Aniruddha 说的那样。
  • 感谢您的回答。我的意思是一个圆圈上的按钮。它是 png 图像(它不是必需的,所以它可以是带有选择器的 xml)。我不想对所有视图使用带 id 的 RelativeLayout,因为我有很多自定义子布局,而不是我应该使用 ListView

标签: android listview button rounding


【解决方案1】:

如果你想要圆形按钮,那么在 drawable 文件夹中创建一个名为 round.xml 的 XML 文件。

然后将以下内容添加到xml文件中

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#e5e4e2" />
        <corners android:radius="3dp" />
    </shape>

然后将其设为按钮的background

      <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/myButton"
            android:background="@drawable/round" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    • 2012-08-28
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多