Layout_constraintwidth_default="wrap" Is Deprecated Any Alternative?
Solution 1:
Following are the changes i have made for solution, imageview will not go outside the visible screen area :
android:layout_width="wrap_content"app:layout_constrainedWidth="true"app:layout_constraintHorizontal_bias="0"app:layout_constraintHorizontal_chainStyle="packed"
<androidx.constraintlayout.widget.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/text"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Text asdasdasdasdasdasdasdasdasdadsasdasdasdasdasdasdasd"app:layout_constrainedWidth="true"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toStartOf="@+id/image"app:layout_constraintHorizontal_bias="0"app:layout_constraintHorizontal_chainStyle="packed"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><ImageViewandroid:id="@+id/image"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@mipmap/ic_launcher"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toEndOf="@+id/text"app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>
Solution 2:
You can try this:
android:layout_width="wrap_content"app:layout_constrainedWidth="true"
width cannot be “0dp”
Solution 3:
As the documentation says in this link from Android Developers:
In versions before 1.1 they will be treated as a literal dimension -- meaning, constraints will not limit the resulting dimension. While in general, this is enough (and faster), in some situations, you might want to use WRAP_CONTENT, yet keep enforcing constraints to limit the resulting dimension. In that case, you can add one of the corresponding attributes:
app:layout_constrainedWidth="true|false"
Hence, use layout_constrainedWidth="true"
instead of layout_constraintWidth_default="wrap"
.
Solution 4:
If a dimension is set to WRAP_CONTENT
, in versions before 1.1 they will be treated as a literal dimension-meaning, constraints will not limit the resulting dimension.
It’s often required that view width or height to remain as wrap content instead of match constraint or match parent but unfortunately wrap content override the constraint applied and overlap with the constraint if width or height changes. With version 1.1.0 this issue is resolved by using
app:layout_constrainedWidth="true"OR app:layout_constrainedHeight="true"
FYI
You can use percentage
for width and height the dimension should be match constraint(0dp)
and app:layout_constraintWidth_default="percent"
or app:layout_constraintHeight_default="percent"
need to set as percent.
Example
<TextView
android:id="@+id/txtView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello Width In Percentage"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.5"
app:layout_constraintLeft_toLeftOf="parent" />
GRADLE
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'// For androidx
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
Post a Comment for "Layout_constraintwidth_default="wrap" Is Deprecated Any Alternative?"