标签: android-constraintlayout

RecycleView 不滚动

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/bottomSheetLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_top_round_corner">

    <androidx.cardview.widget.CardView
    android:id="@+id/cardViewInnerProductContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    app:cardElevation="10dp"
    app:cardCornerRadius="10dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/closeIv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="12dp"
            android:src="@drawable/ic_close_dark"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/changeAddressTitleTv"
            style="@style/FontLocalizedBold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="7dp"
            android:paddingStart="12dp"
            android:text="@string/changeaddress_popup_change_address"
            android:textColor="@color/colorTextPrimary"
            android:textSize="20sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@id/closeIv" />

        <View
            android:id="@+id/divider"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/colorDividerLight"
            app:layout_constraintTop_toBottomOf="@id/closeIv" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/locationRv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/divider"
            tools:listitem="@layout/item_choose_address" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/addressesRv"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            android:paddingBottom="4dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/locationRv"
            tools:listitem="@layout/item_choose_address" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>



        val addressesLayoutManager = …
Run Code Online (Sandbox Code Playgroud)

android scroll kotlin android-recyclerview android-constraintlayout

0
推荐指数
1
解决办法
1766
查看次数

Android约束布局textview来包装上下文并在没有更多空间时显示椭圆

我想使用能够满足的约束布局

(1) 包裹第二个TextView的内容 在此输入图像描述

(2) 延长第二个 TextView 的宽度,直到没有空格时显示省略号。 在此输入图像描述

所有这 3 个 TextView 都在同一行,并且非常需要背景颜色。

<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:background="@android:color/white"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:background="@android:color/darker_gray"
        android:padding="4dp"
        android:text="Text View 1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/text2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:background="@android:color/holo_green_light"
        android:ellipsize="end"
        android:gravity="fill"
        android:maxLines="1"
        android:padding="4dp"
        android:text="Short Text "
        app:layout_constraintBottom_toBottomOf="@+id/text1"
        
        app:layout_constraintStart_toEndOf="@+id/text1"
        app:layout_constraintTop_toTopOf="@+id/text1" />

    <TextView
        android:id="@+id/text3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:background="@android:color/holo_orange_dark"
        android:padding="4dp"
        android:text="Text View 3"
        android:textAlignment="center"
        app:layout_constraintBottom_toBottomOf="@+id/text1"
        app:layout_constraintEnd_toEndOf="parent"

        app:layout_constraintTop_toTopOf="@+id/text1" />

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

android android-constraintlayout

0
推荐指数
1
解决办法
302
查看次数

Android - ConstraintLayout 内的 TextView 向右无穷大 - 如何与 ImageView 固定并也有省略号

我试图让我的TextView宽度具有动态宽度并ImageView固定在它的末端,在ConstraintLayout. 当文本很长时,我想使用省略号并将其ImageView固定在其右侧的视图上。

这是我试图在视觉上实现的目标的示例:

在此输入图像描述

在此输入图像描述

使用我的代码,我能够获得第一张图像,thisIsShortText但是当我有长文本时,它看起来很糟糕,如下所示:

在此输入图像描述

在此输入图像描述

和只是向右延伸到无穷大TextViewImageView谁能帮我解决这个问题吗?这是我的 XML 代码。如果你只是将它放入你的 Android Studio 中,它看起来就像我的图像。谢谢你:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="70dp">

    <!-- This view does not move or change size. -->
    <View
        android:id="@+id/firstView"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:background="@android:color/holo_red_dark"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </View>

    <!-- This view's width is dynamic and changes size based on it's text length.
     If the length of text is too long to fit, it uses an …
Run Code Online (Sandbox Code Playgroud)

android textview android-layout android-xml android-constraintlayout

0
推荐指数
1
解决办法
896
查看次数

使用 ConstraintLayout 创建内容行

我目前遇到了一个相对复杂的基于 ConstraintLayout 的设计实现的复杂情况。

在此输入图像描述

该设计是一排项目,如上所示。这些行是静态的,并根据某些数据相关条件显示/隐藏。

我遇到的问题是,我还没有找到一种可靠的方法来正确包含布局中的分隔线/屏障之间的每一行。

在此输入图像描述

正如您在上图中看到的,我的约束布局不符合预期的障碍/分隔线。我在下面包含了此布局的 XML。

 <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="16dp"
            android:paddingRight="16dp">

                <ImageView
                    android:id="@+id/timeIcon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_clock"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/timeTextView"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:textColor="#FF354052"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    app:layout_constraintEnd_toStartOf="@id/statusTextView"
                    app:layout_constraintStart_toEndOf="@+id/textGuideline"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:text="4:20 PM" />

                <com.weedmaps.driver.android.view.StatusTextView
                    android:id="@+id/statusTextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingBottom="4dp"
                    android:paddingEnd="27dp"
                    android:paddingStart="27dp"
                    android:paddingTop="4dp"
                    android:textAllCaps="true"
                    android:textSize="12sp"
                    android:textStyle="bold"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:background="@color/accepted_blue" />

                <android.support.constraint.Barrier
                    android:id="@+id/headerDividerTopBarrier"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:barrierDirection="top"
                    app:constraint_referenced_ids="headerDivider" />

                <!-- / end delivery status section -->

                <android.support.constraint.Barrier
                    android:id="@+id/deliveryStatusSectionBottomBarrier"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:barrierDirection="bottom"
                    app:constraint_referenced_ids="statusTextView, timeTextView, timeIcon" />

                <View
                    android:id="@+id/headerDivider"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#FFE6EAEE"
                    app:layout_constraintTop_toBottomOf="@id/deliveryStatusSectionBottomBarrier"
                    app:layout_constraintBottom_toTopOf="@id/destinationInfoSectionTopBarrier" /> …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

-1
推荐指数
1
解决办法
2149
查看次数

Android 工作室布局编辑器。等待构建完成

即使没有构建发生,Android Studio 布局预览也停留在等待构建完成。我已经使 android studio 无效并重新启动。我已经卸载并重新安装。它仍然有同样的问题。我注意到这是在我创建了一个带有约束布局的 xml 文件之后开始的。我已经删除了它,但这没有帮助。

android android-studio android-constraintlayout android-layout-editor

-1
推荐指数
1
解决办法
426
查看次数

-3
推荐指数
1
解决办法
604
查看次数