gpt4 book ai didi

android - 更改单选按钮在 ListView 中的位置

转载 作者:太空狗 更新时间:2023-10-29 15:54:09 26 4
gpt4 key购买 nike

我有个小问题。我有一个 ListView,我使用:

ArrayAdapter adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice,
data);

有单选列表。但在这个解决方案中,我在右侧有一个单选按钮,但我想将它们放在左侧。我该怎么做?

编辑:我的 xml 文件:

<LinearLayout     
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="92.5">
<TextView
android:id="@+id/user_account_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="109dp"
android:text="@string/user_account_text"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ListView
android:id="@+id/user_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:scrollbars="vertical"
android:layout_marginRight="100dp"
android:layout_weight="1"
android:layout_marginLeft="100dp">
</ListView>

<Button
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center"
android:text="@string/login"
android:background="@drawable/button"
android:textColor="@android:color/white"/>

</LinearLayout>

最佳答案

新建xml布局并复制android.R.layout.simple_list_item_single_choice的源代码( here )

然后,

  1. 更改 android:checkMark="?android:attr/listChoiceIndicatorSingle"android:checkMark="@null"
  2. 添加新行: android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
    或者如果你想要复选框,那么使用这个:
    android:drawableLeft="?android:attr/listChoiceIndicatorMultiple"
  3. 在您的代码中使用这个新布局:
    ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.YOUR_NEW_XML, data);

此线程可能对您有所帮助:How do I make the Checkbox in Android CheckedTextView be left aligned instead of right aligned?

关于android - 更改单选按钮在 ListView 中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17207769/

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