0

只是无法将我的列表视图中的文本右/左对齐。不知道该怎么做。Android:重力似乎不起作用。

这是我的xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background= "#FFCC00"
tools:context=".MainActivity" >

<RelativeLayout
    android:layout_weight="0.5"
    android:layout_width="fill_parent"
    android:layout_height="0dip">
    <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:divider="@null"
        android:dividerHeight="0dp"
        tools:listitem="@android:layout/simple_list_item_1" 
        android:background= "#FFCC00"
        android:textColor="#330033"
        android:gravity="left">

    </ListView>
</RelativeLayout>

<RelativeLayout
    android:layout_weight="9"
    android:layout_width="fill_parent"
    android:layout_height="0dip">
        <TextView
        android:id="@+id/bookMark"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textStyle="bold"
        android:gravity="center"
        android:text="Bookmarks"
        android:textColor="#330033"
        android:background= "#CCCC99"
        android:onClick="loadBookmarks"/>
</RelativeLayout>

这是填充列表视图的代码

lv = (ListView) findViewById(R.id.listView1);
    lv.setAdapter(new ArrayAdapter<String>(this,R.layout.row_listview, getResources().getStringArray(R.array.Stories)));
4

2 回答 2

0

我相信这就是您正在寻找的。

android:textAlignment="center"

android:gravity仅当总文本小于视图时才使用。因此,如果您有“包装内容”,那么我认为它不会起作用。至少这是它在网站TextView上所说的

下面我为将两个文本视图与行的左侧和右侧对齐的行添加了示例布局和相关代码

 private ListView lv = null;
 @Override
public View onCreateView(LayoutInflater inflate, ViewGroup container,
        Bundle savedInstanceState) {
    View result = inflate.inflate(R.layout.lists_layout, container, false);
    lv = (ListView) findViewById(R.id.listView1);

    adapter = new SimpleAdapter(context, things, R.layout.rowLayout, from, to);
    lv.setAdapter(adapter);
}

列表布局.xml

<?xml version="1.0" encoding="utf-8"?>

<ListView
    android:id="@+id/listView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     >

</ListView>

行布局.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="5dp" >


    <TextView
        android:id="@+id/textleft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft = "true"
         />

    <TextView
        android:id="@+id/textright"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight = "true" />
</LinearLayout>

于 2013-01-17T20:48:59.163 回答
0

您可能想要更改 R.layout.row_listview 内 textview 中的文本。请分享 row_listview.xml 中的代码,以便我们为您提供帮助。

于 2013-01-17T21:55:49.537 回答