I have created a login page which has two editText fields for username and password. I have included an ImageView in the activity also.
I have made an XML file to make rounded white background for the editText fields. However, that did not work and was still transparent. On changing the background from the created XML file to simple white colour, I could still not see the editText fields.
Below is the code I have used for the following:
Login.XML
<?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/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:onClick="Clicked"
android:padding="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
tools:context=".MainActivity">
<Button
android:id="#+id/button"
android:layout_width="307dp"
android:layout_height="63dp"
android:layout_marginBottom="17dp"
android:layout_marginEnd="327dp"
android:layout_marginStart="84dp"
android:foreground="#drawable/emailsignup"
android:text="#string/button"
app:layout_constraintBottom_toTopOf="#+id/editTextTextPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.104"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button2"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="#+id/button2"
android:layout_width="293dp"
android:layout_height="57dp"
android:layout_marginEnd="146dp"
android:layout_marginStart="63dp"
android:layout_marginTop="200dp"
android:foreground="#drawable/gmailsignup"
android:text="#string/button2"
app:layout_constraintBottom_toTopOf="#+id/button"
app:layout_constraintEnd_toStartOf="#+id/imageView"
app:layout_constraintHorizontal_bias="0.006"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button3"
android:layout_width="88dp"
android:layout_height="48dp"
android:layout_marginBottom="269dp"
android:layout_marginEnd="253dp"
android:layout_marginStart="150dp"
android:layout_marginTop="43dp"
android:background="#drawable/loginbg"
android:fontFamily="monospace"
android:text="#string/LoginText"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/imageView"
app:layout_constraintEnd_toStartOf="#+id/imageView"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editTextTextPassword"
app:layout_constraintVertical_bias="0.0" />
<EditText
android:id="#+id/editTextTextPassword"
android:layout_width="228dp"
android:layout_height="51dp"
android:layout_marginBottom="132dp"
android:layout_marginEnd="95dp"
android:layout_marginStart="179dp"
android:layout_marginTop="430dp"
android:autofillHints=""
android:background="#drawable/edittextround"
android:ems="10"
android:fontFamily="sans-serif-medium"
android:hint="#string/PasswordHint"
android:inputType="textPassword"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="#+id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.978"
app:layout_constraintStart_toEndOf="#+id/imageView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<EditText
android:id="#+id/editTextTextPersonName"
android:layout_width="281dp"
android:layout_height="54dp"
android:layout_marginBottom="320dp"
android:layout_marginEnd="153dp"
android:layout_marginStart="58dp"
android:layout_marginTop="88dp"
android:autofillHints=""
android:ems="10"
android:background="#drawable/edittextround"
android:hint="#string/LoginTextHint"
android:inputType="textPersonName"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageView"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView"
app:layout_constraintVertical_bias="0.962" />
<ImageView
android:id="#+id/imageView"
android:layout_width="566dp"
android:layout_height="972dp"
android:adjustViewBounds="false"
android:contentDescription="#string/todo"
android:cropToPadding="false"
android:foreground="?android:attr/selectableItemBackgroundBorderless"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.344"
app:srcCompat="#drawable/picture1_2" />
</androidx.constraintlayout.widget.ConstraintLayout>
edittextround.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<gradient
android:centerY="0.2"
android:startColor="#D3D3D3"
android:centerColor="#65FFFFFF"
android:endColor="#00FFFFFF"
android:angle="270"
/>
<stroke
android:width="0.7dp"
android:color="#BDBDBD" />
<corners
android:radius="15dp" />
</shape>
I tried putting the edittextbackground.xml on the login button and it worked perfectly.
The images related to this activity are below:
Image of the design
Please help me figure out why my editText fields do not show their backgrounds
ok got it
so the problem is below
app:layout_constraintBottom_toTopOf="#+id/imageView"
app:layout_constraintTop_toBottomOf="#+id/imageView"
you are setting the constraints to imageView and that imageView also renders in the area of Editext but not in the background because it is at same elevation as of Editexts so if you just increase the elevation of of editexts they will show up , i tried it , it works
just add android:elevation="1dp" in both edittexts the imageview is at 0dp so editext will show above it.
Although it works but your constraints are confusing use parent instead
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/button" will also do
also i want to say if you use constraint layout correctly you will not need to set layout_width and layout_height in most cases you can set them to 0 the constraints will determine the correct width and height also you don't need to use margins your constraint will handle them if you use bias, chains, groups ,barrier, guidelines etc correctly , please learn more about constraint layout and you can reduce the lines in above layout file to half.
this tutorial will give you good start, also watch other videos in that series
have a good day
Related
I have this Drawable aiming to make my round button:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimary"/>
<corners android:radius="150dp"/>
</shape>
</item>
</selector>
I call him in the background of my button normally ...
<Button
android:id="#+id/btnPhoto"
android:background="#drawable/bg_btn_rounded"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="8dp"
android:layout_marginTop="42dp"
android:layout_marginEnd="8dp"
android:text="#string/btnphoto"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
But no changes are applied to the component, I tried to use Drawable on other components and it doesn't apply ... I have no idea why this happens.
My complete screen:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.misael.appchat.RegisterActivity">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tUsername"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:hint="#string/usernameHint"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/btnPhoto">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editUsername"
android:layout_width="match_parent"
android:layout_height="68dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tEmail"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginTop="24dp"
android:hint="#string/loginHint"
app:layout_constraintEnd_toEndOf="#+id/tUsername"
app:layout_constraintStart_toStartOf="#+id/tUsername"
app:layout_constraintTop_toBottomOf="#+id/tUsername">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editEmail"
android:layout_width="match_parent"
android:layout_height="68dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tSenha"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginTop="24dp"
android:hint="#string/passwordHint"
app:layout_constraintEnd_toEndOf="#+id/tEmail"
app:layout_constraintStart_toStartOf="#+id/tEmail"
app:layout_constraintTop_toBottomOf="#+id/tEmail">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editPassword"
android:layout_width="match_parent"
android:layout_height="68dp"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/btnRegister"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="58dp"
android:layout_marginTop="32dp"
android:text="#string/signinButton"
android:textColor="#7517bd"
app:layout_constraintEnd_toEndOf="#+id/tSenha"
app:layout_constraintStart_toStartOf="#+id/tSenha"
app:layout_constraintTop_toBottomOf="#+id/tSenha" />
<Button
android:id="#+id/btnPhoto"
android:background="#drawable/bg_btn_rounded"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="8dp"
android:layout_marginTop="42dp"
android:layout_marginEnd="8dp"
android:text="#string/btnphoto"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
If you are using a Material Theme there is an auto-inflation enabled which will replace <Button> with <com.google.android.material.button.MaterialButton> at runtime.
Check also this question.
Just use the app:backgroundTint attibute to define the background color and the app:cornerRadius to define the corner radius.
Something like:
<com.google.android.material.button.MaterialButton
android:id="#+id/btnPhoto"
app:backgroundTint="#color/primaryLightColor"
app:cornerRadius="150dp"
android:layout_width="150dp"
android:layout_height="150dp"/>
Are you using a Material Components theme? If so, your <Button> tag will be inflated as a com.google.android.material.button.MaterialButton. The documentation for this widget states:
Do not use the android:background attribute. MaterialButton manages its own background drawable, and setting a new background means MaterialButton can no longer guarantee that the new attributes it introduces will function properly.
If you don't want special MaterialButton behavior, you can explicitly specify a different button class to use. Change your <Button> tag to this instead:
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btnPhoto"
android:background="#drawable/bg_btn_rounded"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="8dp"
android:layout_marginTop="42dp"
android:layout_marginEnd="8dp"
android:text="#string/btnphoto"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /
I would like to achieve the following layout
The bottom layover TextView has a rounded rectangle drawable as a background. I would like to align the text inside the TextView with the top text. Currently what happens is that the rounded edges align with the text and not the actual text.
Any ideas on how to implement this with ConstraintLayout? I tried setting layout_constraintStart_toStartOf the text above and set negative padding but I guess constraints have priority here and ignores the padding.
Here is the full xml layout:
<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="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/trip_type_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:tint="#color/oslo_gray"
app:layout_constraintBottom_toBottomOf="#+id/trip_month"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/trip_date"
app:srcCompat="#drawable/ic_car_pickup" />
<View
android:id="#+id/divider"
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:background="#color/oslo_gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/trip_type_icon" />
<TextView
android:id="#+id/trip_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textColor="#color/shark"
app:layout_constraintEnd_toEndOf="#+id/trip_month"
app:layout_constraintStart_toEndOf="#+id/trip_type_icon"
app:layout_constraintTop_toTopOf="parent"
tools:text="5" />
<TextView
android:id="#+id/trip_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:textColor="#color/emperor"
app:layout_constraintBottom_toBottomOf="#+id/trip_timeline_subtitle"
app:layout_constraintStart_toEndOf="#+id/trip_type_icon"
app:layout_constraintTop_toBottomOf="#+id/trip_date"
tools:text="Sep" />
<TextView
android:id="#+id/trip_timeline_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textColor="#color/shark"
app:layout_constraintEnd_toStartOf="#+id/navigate_arrow"
app:layout_constraintStart_toEndOf="#+id/trip_date"
app:layout_constraintTop_toTopOf="parent"
tools:text="PVG -> PEK" />
<TextView
android:id="#+id/trip_timeline_subtitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="48dp"
android:textColor="#color/emperor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/trip_timeline_title"
app:layout_constraintStart_toEndOf="#+id/trip_date"
app:layout_constraintTop_toBottomOf="#+id/trip_timeline_title"
tools:text="2:10pm - 4:45pm" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/navigate_arrow"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="24dp"
app:layout_constraintBottom_toBottomOf="#+id/trip_timeline_subtitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/trip_timeline_title"
app:layout_constraintTop_toTopOf="#+id/trip_timeline_title"
app:srcCompat="#drawable/ic_arrow_right_vector" />
<TextView
android:id="#+id/trip_timeline_flight_layover"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_rectangle_radius_12dp"
android:textColor="#color/emperor"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="#id/navigate_arrow"
app:layout_constraintStart_toStartOf="#+id/trip_timeline_subtitle"
app:layout_constraintTop_toBottomOf="#id/trip_timeline_subtitle"
tools:background="#drawable/rounded_rectangle_radius_12dp"
tools:text="2h 25m Layover at PEK"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>
Rounded rectangle drawable rounded_rectangle_radius_12dp:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:tint="#color/porcelain">
<corners android:radius="12dp" />
<padding android:left="12dp"
android:right="12dp"
android:top="2dp"
android:bottom="2dp"/>
</shape>
I would define padding inside your trip_timeline_flight_layover TextView instead of your drawable:
<TextView
android:id="#+id/trip_timeline_flight_layover"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:background="#drawable/rounded_rectangle_radius_12dp"
android:textColor="#color/emperor"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="#id/navigate_arrow"
app:layout_constraintStart_toStartOf="#+id/trip_timeline_subtitle"
app:layout_constraintTop_toBottomOf="#id/trip_timeline_subtitle"
tools:background="#drawable/rounded_rectangle_radius_12dp"
tools:text="2h 25m Layover at PEK"
tools:visibility="visible" />
And then set layout_marginStart of trip_timeline_title equal to the padding of your layover``TextView, in this case, 12dp.
EDIT:
I actually don't think you have to define padding inside your TextView, just making margin of your title equal to the side padding should work.
Iam designing a food ordering page, so i need to use small button to add the food on cart.The problem was when i giving 24dp width and height the button size reduces but i cant able to add the text("+" "-").
I have tried
android:minWidth="0dp"
android:minHeight="0dp"
style="?android:attr/negativeButtonText"
<android.support.design.button.MaterialButton
android:id="#+id/incrementButtton"
style="?android:attr/buttonStyleSmall"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:gravity="center"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="+"
android:textColor="#color/ash"
android:textSize="#dimen/fm_food_price_text_size" />
I want to know how to set button 24dp and show "+" text. as like below image.
In this image i used textView, so text is visibile. I want this by using button.
Try this way. This is much more efficient
<android.support.constraint.ConstraintLayout
android:layout_width="#dimen/_dp_85"
android:layout_height="#dimen/_dp_35"
android:id="#+id/quantityviewer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/productName"
android:background="#drawable/quantity"
app:layout_constraintBottom_toBottomOf="#+id/productName">
<TextView
android:textColor="#color/black"
android:text="#string/_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/quantity"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="#+id/increase"
app:layout_constraintStart_toEndOf="#+id/decrease"
/>
<ImageView
app:layout_constraintStart_toStartOf="#id/quantityviewer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/decrease"
app:layout_constraintEnd_toStartOf="#id/quantity"
android:src="#drawable/ic_minus"
app:layout_constraintTop_toTopOf="#id/quantityviewer"
app:layout_constraintBottom_toBottomOf="#id/quantityviewer"
android:contentDescription="#string/todo"
/>
<ImageView
app:layout_constraintEnd_toEndOf="#id/quantityviewer"
android:layout_width="wrap_content"
android:src="#drawable/ic_plus"
android:layout_height="wrap_content"
android:id="#+id/increase"
app:layout_constraintTop_toTopOf="#id/quantityviewer"
app:layout_constraintBottom_toBottomOf="#id/quantityviewer"
android:contentDescription="#string/todo" app:layout_constraintStart_toEndOf="#+id/quantity"
/>
</android.support.constraint.ConstraintLayout>
quantitiy.xml(shape of the layout)
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/listview_background_shape">
<corners android:radius="#dimen/_dp_5" />
<stroke
android:width="#dimen/_dp_1"
android:color="#color/quantitystokecolor" />
</shape>
I have solved by using ImageButton instead of button.
<ImageButton
android:id="#+id/incrementButtton"
android:layout_width="24dp"
android:layout_height="24dp"
android:padding="8dp"
android:layout_gravity="center"
android:gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/ic_minus_symbol"
android:scaleType="centerInside"
/>
for ripple effect i used
android:background="?attr/selectableItemBackgroundBorderless"
I'm trying to create a bulleted list in Android where the bullet is aligned to the vertical center of the first line in a TextView like so:
The XML for a single bullet/text row is this:
<android.support.constraint.ConstraintLayout
android:id="#+id/setup_intro_bullet_first_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/setup_intro_bullet_first"
style="#style/TextAppearance.AppCompat.Headline"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/bullet"
android:textColor="#color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/setup_intro_bullet_first_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:paddingTop="14dp"
android:text="#string/setup_intro_benefit_notification"
android:textColor="#android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#id/setup_intro_bullet_first"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Here I use padding on the TextView to align with the bullet, but this is not a solution because the alignment isn't consistent across other resolutions. I've also tried putting the bullet character in the text string itself but then the second line of text will sit under the bullet, which is not what I want. I'd like some advice on how to accomplish this.
The solution I came up with is to create a circle Drawable and use it in an ImageView. You can define the baseline of an ImageView which allowed me to properly align it with the baseline of the TextView. Here is the circle XML:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/colorAccent" />
</shape>
And the layout XML:
<ImageView
android:id="#+id/setup_intro_bullet_first"
style="#style/TextAppearance.AppCompat.Headline"
android:layout_width="4dp"
android:layout_height="4dp"
android:baseline="7dp"
android:src="#drawable/circle"
app:layout_constraintBaseline_toBaselineOf="#+id/setup_intro_bullet_first_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/setup_intro_bullet_first_text" />
<TextView
android:id="#+id/setup_intro_bullet_first_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
style="#style/TextAppearance.AppCompat.Subhead"
android:text="#string/setup_intro_benefit_notification"
android:textColor="#android:color/white"
app:layout_constraintLeft_toRightOf="#id/setup_intro_bullet_first"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Use the app:layout_constraintBaseline_toBaselineOf attribute to constrain your "bullet" view's baseline to the baseline of your text view.
Constraints for your bullet view:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/setup_intro_bullet_first_text"
app:layout_constraintBaseline_toBaselineOf="#+id/setup_intro_bullet_first_text"
And for your text:
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#id/setup_intro_bullet_first"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
I have follow situation.
I am using toggle button with custom background and image. For image composition I have created layer with puts my #drawable/image over #drawable/background, in addition to this my #drawable/background is a selector of two backgrounds: check and unchecked.
Now I have 5 button and all this buttons are placed into LinearLayout horizontally, I have tried to fill spaces by adding layout-weight="1", but in this case icons are stretchered too.
I have tried scale, but scale should be root element, not part of my selector or layer.
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/ui_bottom_shadow"
android:elevation="2dp"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<ImageButton
android:id="#+id/button_back"
style="#style/IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_arrow_back"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="#+id/button_call"
style="#style/IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:src="#drawable/ic_phone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="#id/button_favourite"
app:layout_constraintTop_toTopOf="parent" />
<ToggleButton
android:id="#+id/button_favourite"
style="#style/IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textOff=""
android:textOn=""
android:background="#drawable/ui_favourite_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>