【问题标题】:How do I add a 1dp line to the bottom of my textview cell ( not a table layout)如何在我的 textview 单元格底部添加 1dp 行(不是表格布局)
【发布时间】:2013-05-20 08:24:35
【问题描述】:

我是 android 新手,只是一个非常简单的问题,我如何在文本视图中添加底线,使其以 1dp 的形式出现在单元格的底部,这是到目前为止的代码:

<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="47.5dp"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="2dp"
        android:paddingTop="13dp"
        android:background="@drawable/line_str"
        android:paddingLeft="8dp"
        android:text="@string/manage_categories"
        android:singleLine="true"
        android:textColor="@color/white"
        android:fontFamily="Roboto-Regular"
        android:layout_gravity="center"
        android:textSize="16sp"
        />

line_str.xml如下:

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


<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the main color -->
<item>
  <shape>
        <solid android:color="@color/black" />
  </shape>
</item>
<!-- This is the line -->
<item android:bottom="1dp">
 <shape>
       <solid android:color="#252525" />
 </shape>
</item>
</layer-list>

任何帮助表示赞赏。谢谢!

【问题讨论】:

    标签: android android-layout listview android-intent android-emulator


    【解决方案1】:

    我会放置一个水平扩展的 9patch 图像并将其添加到 textview 的 drawableBottom 属性中。

    至于层列表方法试试这个:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- This is the main color -->
    <item>
      <shape>
            <size android:height="@dimen/textViewHeight"/>
            <solid android:color="@color/black" />
      </shape>
    </item>
    <!-- This is the line -->
    <item android:top="@dimen/textViewHeight">
     <shape>
           <size android:height="1dp"/>
           <solid android:color="#252525" />
     </shape>
    </item>
    </layer-list>
    

    【讨论】:

    • 什么是@dimen/textviewheight?
    • 这将是您在 dimens.xml 文件夹中的 textView 高度的声明。或者您可以在此处对值本身进行硬编码。
    猜你喜欢
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 2022-01-12
    • 2021-06-06
    • 2017-05-19
    • 2020-06-05
    相关资源
    最近更新 更多