Android-如何在ListView或ExpandableListView中设置TextView的填充 [英] Android - How to set padding for TextView in ListView or ExpandableListView

查看:83
本文介绍了Android-如何在ListView或ExpandableListView中设置TextView的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在ListViewExpandableListView的每一行中为TextView设置填充. 我尝试使用android:padding和子级(paddingLeft,...),但没有任何结果.我能怎么做? 谢谢

I need to set padding for the TextView in every row of ListView or ExpandableListView. I try to use android:padding and child (paddingLeft,...) but without any results. How can I do? Thanks

这是ExpandableListView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="20dp" >

    <TextView 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="wrap_content"
        android:id="@+id/titleScheda"
        android:text="TextView"
        android:layout_width="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:padding="20dp" />

</LinearLayout>

即使仅在2个标记之一中设置了填充,也无法在布局和TextView上设置填充.

Setting padding on both layout and TextView doesn't work, even if the padding is set in only one of the 2 tags.

已解决.问题出在Java代码的SimpleExpandableListAdapter声明中.使用标准布局是无法自定义的,但是对可扩展内容使用自定义布局是使我们能够自定义任何内容的解决方案.

Solved. The problem was in the Java code, in the SimpleExpandableListAdapter declaration. Using the standard layout it's impossible to customize, but using a custom layout for the expandable content is the solution that allows us to customize anything.

推荐答案

我假设您正在使用模板文件(xml布局)在列表视图中添加项目.如果不是,则必须首先实现它.

I assume you're adding the items in the listview using a template file (xml layout). If you're not, you have to implement that first.

在该布局文件中,您可以执行以下操作:

In that layout file you could do this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp" >
    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/text" />
</LinearLayout>

LinearLayout将创建填充并环绕TextView.

The LinearLayout will create the padding and wrap around the TextView.

这篇关于Android-如何在ListView或ExpandableListView中设置TextView的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆