【发布时间】:2015-01-06 22:22:58
【问题描述】:
我将一个布局 ass headerView 附加到我的列表视图中。但是,当我这样做时,它会失去它的风格(即 drawableLeft 改变位置)。
这是标题视图:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/header"
style="@style/header"
android:drawableLeft="@drawable/ic_setup"
android:text="@string/fragment_contacts"
android:contentDescription="@string/fragment_contacts"
android:textSize="@dimen/text_size_medium"
android:layout_gravity="center_horizontal"
android:onClick="readMe"
android:textColor="?attr/color1" />
这就是我将它添加到列表视图的方式
((TextView) header).setText(getString(R.string.fragment_favorites));
listView.addHeaderView(header, null, false);
这是渲染listView并且drawableLeft改变位置时的最终结果:
如何将 DrawableLeft 保持在文本旁边的正确位置?
【问题讨论】:
-
为什么不使用水平的
LinearLayout和ImageView和TextView?