gpt4 book ai didi

android - 无法右对齐android studio中的复选框

转载 作者:行者123 更新时间:2023-11-29 19:15:10 25 4
gpt4 key购买 nike

enter image description here

我正在尝试按照上图进行设计。我尝试了网格布局,也尝试了嵌套线性布局。在这两种方式中,复选框都没有右对齐。它显示在 text1 之后

有人可以帮忙吗。

代码是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="2dp"
tools:context="com.example.user.recycleview.MainActivity">

<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="3">

<ImageView
android:layout_width="80dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:layout_row="0"
android:layout_column="0"
android:layout_rowSpan="2"
android:src="@drawable/cappuccino"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:layout_margin="8dp"
android:maxLines="3"
android:text="@string/cappuccino"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:layout_row="1"
android:layout_column="1"
android:layout_margin="8dp"
android:maxLines="1"
android:text="@string/price"/>

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_row="0"
android:layout_column="2"
android:layout_rowSpan="2" />

</GridLayout>


<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:background="@color/colorPrimary"/>

</LinearLayout>

上面的代码显示如下:

enter image description here

如果 Text1 部分太长,复选框会超出屏幕,如下图所示

enter image description here

最佳答案

您可以通过使用单个 RelativeLayout 来实现这一点。

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="2dp"
tools:context="com.example.user.recycleview.MainActivity">

<ImageView
android:id="@+id/image"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
android:src="@drawable/somepngfile"/>

<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"/>

<TextView
android:id="@+id/text_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
android:layout_toLeftOf="@id/checkbox"
android:layout_margin="8dp"
android:maxLines="2"
android:ellipsize="end"
android:text="This is two line text for your large title This is two line text for your large title"/>

<TextView
android:id="@+id/text_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/text_title"
android:layout_alignLeft="@id/text_title"
android:layout_alignRight="@id/text_title"
android:maxLines="1"
android:text="Price: 150.00"/>

<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"/>

</RelativeLayout>

输出:

enter image description here

关于android - 无法右对齐android studio中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43783889/

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