我想更改列表的重力视图,即相对布局内部的适配器内部


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.golan.wazap.UsersListActivity"
android:orientation="vertical"
android:weightSum="10"
android:background="@drawable/chat_background">
<ListView
    android:id="@+id/myUsers"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

这是我的XML,我不知道我是否需要添加一些东西

public class UsersListAdapter extends BaseAdapter {
private final LinkedList<String> chat;
private final Context context;

public UsersListAdapter(Context context, LinkedList<String> chat) {
    this.context = context;
    this.chat = chat;
}
@Override
public int getCount() {
    return chat.size();
}
@Override
public String getItem(int i) {
    return chat.get(i);
}
@Override
public long getItemId(int i) {
    return i;
}
@Override
public View getView(int i, View recycledView, ViewGroup parent) {
    if (recycledView == null) recycledView = new TextView(context);
    TextView tv = ((TextView) recycledView);
    tv.setText(getItem(i));
    tv.setTextSize(30);
    tv.setTextColor(Color.WHITE);
    tv.setBackgroundResource(R.drawable.chat_bubble);
    tv.setGravity(Gravity.NO_GRAVITY);
    tv.setGravity(Gravity.CENTER_HORIZONTAL);


    return recycledView;
}

}这是我的适配器广告您可以看到我试图将重力更改为center_horizontal,但没有起作用。我需要它位于该列表视图中的行中心

尝试设置android:线性层状的将是center_horizontal或android:layout_gravite of centerview to center_horizontal.i to center_horizontal.i不看到Relativelayout。

最新更新