Android - 如何在ListView或ExpandableListView中为TextView设置填充

时间:2012-09-03 14:54:16

标签: android listview textview padding expandablelistview

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

编辑:

这是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>

在布局和TextView上设置填充不起作用,即使填充仅在2个标记中的一个中设置。

编辑:

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

3 个答案:

答案 0 :(得分:13)

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

在该布局文件中,您可以这样做:

<?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。

答案 1 :(得分:3)

for(int i=0; i< listview.getChildCount();i++) 

  listview.getChildAt(i).setPadding(10,10,10,10);

答案 2 :(得分:0)

您可以按如下方式添加填充:

docker exec -it <my-app id> /bin/bash
相关问题