我正在尝试向 ListView 添加图像,使其看起来更像一个按钮。我希望图像小一点,也许是当前的 60%。并且图像可以很好地排列在右侧的一列中。这是我目前拥有的屏幕:
这是我的列表视图 xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:layout_width="match_parent"
android:drawableRight="@drawable/arrow_button"
>
</TextView>
知道我做错了什么吗?
包含此 TextView 的 ListView 定义如下:
需要注意的是,我创建和使用列表的方式是使用 ListAdapter,使用如下代码:
Question q = new Question ();
q.setQuestion( "This is a test question and there are more than one" );
questions.add(q);
adapter = new ArrayAdapter<Question>( this, R.layout.questions_list, questions);
setListAdapter(adapter);
Thanks!
啊。您正在使用复合绘图做正确的事情。不确定是否有更好的方法来扩展复合可绘制的间距,但我知道这会起作用。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true" />
<View
android:layout_height="64dip"
android:layout_width="64dip"
android:background="@drawable/arrow_button"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
基本上只是指出使用父级左右对齐。您可能需要为其添加一些边距或填充。还要确保元素垂直居中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)