簡體   English   中英

如何在約束布局中設置左右文本視圖和單選按鈕?

[英]how to set left and right textview and radio button in constraint layout?

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/phone_number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif"
        android:letterSpacing="0.01"
        android:lineSpacingExtra="32sp"
        android:text="+44 2079460860"
        android:textColor="@color/colorDusk"
        android:textSize="16sp"
        android:textStyle="normal"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif"
        android:lineSpacingExtra="32sp"
        android:text="Mobile UK"
        android:textColor="@color/secondryColor"
        android:textSize="14sp"
        android:textStyle="normal"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/phone_number" />

    <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/radio_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/radio_button_background"
        android:button="@null"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.864"
        app:layout_constraintStart_toEndOf="@+id/phone_number"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

這是我的RecyclerView:

 <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerview"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:paddingTop="25dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/title" />

這是我的布局,我無法在約束布局內設置左側或啟動文本視圖以及右側或末端單選按鈕,我的當前屏幕如下:

這是屏幕截圖:

在此處輸入圖片說明

雖然我希望復選框在右側或約束布局的最后完整顯示,但請建議我如何實現此目的

更新

 <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.AppCompatTextView
            android:id="@+id/phone_number"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif"
            android:letterSpacing="0.01"
            android:lineSpacingExtra="32sp"
            android:text="+44 2079460860"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="16sp"
            android:textStyle="normal"
            app:layout_constraintEnd_toStartOf="@id/radio_button"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <android.support.v7.widget.AppCompatTextView
            android:id="@+id/name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif"
            android:text="Mobile UK"
            android:textColor="@color/colorPrimary"
            android:textSize="14sp"
            android:textStyle="normal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@id/radio_button"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/phone_number" />

        <android.support.v7.widget.AppCompatRadioButton
            android:id="@+id/radio_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>

試試下面的代碼,將android.support.constraint.ConstraintLayout更改為LinearLayout並設置layout weight

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <LinearLayout
        android:layout_weight="1"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.AppCompatTextView
            android:id="@+id/phone_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif"
            android:letterSpacing="0.01"
            android:lineSpacingExtra="32sp"
            android:text="+44 2079460860"
            android:textColor="@color/colorPrimary"
            android:textSize="16sp"
            android:textStyle="normal"
            />

        <android.support.v7.widget.AppCompatTextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif"
            android:lineSpacingExtra="32sp"
            android:text="Mobile UK"
            android:textColor="@color/colorAccent"
            android:textSize="14sp"
            android:textStyle="normal"
            />



    </LinearLayout>

    <LinearLayout
        android:gravity="right"
         android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <android.support.v7.widget.AppCompatRadioButton
            android:id="@+id/radio_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@mipmap/ic_launcher"
            android:button="@null"
            />

    </LinearLayout>



</LinearLayout>

或者,您可以使用以下示例代碼:

在此處輸入圖片說明

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">


<LinearLayout
    android:layout_weight="1"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Mobile UK"
        android:textColor="@color/colorAccent"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="+44 2079460860"
        android:textColor="@color/colorPrimary"
        />

</LinearLayout>

<LinearLayout
     android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <RadioButton
        android:id="@+id/radio_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

</LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM