gpt4 book ai didi

android - 使 listview RelativeLayout 在每个项目上对齐

转载 作者:行者123 更新时间:2023-11-29 00:27:38 26 4
gpt4 key购买 nike

我在 android 上使用 lsitview relativelayout 时遇到问题,结果与我想要的不匹配,

结果是这样的;

enter image description here

我的代码;

<?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:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView4"
android:layout_below="@+id/textView4"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="25dp"
android:layout_toRightOf="@+id/textView1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="25dp"
android:layout_toRightOf="@+id/textView2"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView6"
android:layout_below="@+id/textView6"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="25dp"
android:layout_toRightOf="@+id/textView3"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

我想让它对齐每个项目,就像一个表格,让它更像这样更易于阅读

enter image description here

注意:这是一个listview,我用这段代码把它和android xml布局文件放在一起,上面的代码是针对list1 xml布局文件 下面是 activity

ListAdapter adapter = new SimpleAdapter(LihatBangsal.this, mylistRuper,
R.layout.list1, new String[] { "ruper", "kelas", "nama", "noregis", "rm","umur", "jk" },
new int[] { R.id.textView1, R.id.textView2,R.id.textView3, R.id.textView4, R.id.textView5, R.id.textView6, R.id.textView7});
listBangsal.setAdapter(adapter);

最佳答案

您是否正在尝试使用 TextView 模拟 ListView?如果这是正确的,您需要为每个 TextView 创建或设置一个“样式”,将它们添加为:

android:layout_marginX="<NUMBER>"

其中 X 是左、右、上、下,或者只是设置四个边距的边距。也尝试使用 RelativeLayout 的属性,如 android:layout_alignLeft="<CHILD>"

尝试使用此页面查找 RelativeLayout 属性 Android RelativeLayout

关于android - 使 listview RelativeLayout 在每个项目上对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18223330/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com