问题描述
我需要在ListView
或ExpandableListView
的每一行中为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的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!