Currently, I have this code for this page.
But my preview should that my button is at the center of the second half layout, but in my emulator, it shows it still at the top of the layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_profile">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_img"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/default_person_icon"
app:civ_border_color="#android:color/black"
app:civ_border_width="2dp"
android:layout_centerInParent="true"
android:layout_marginTop="100dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Email"
android:textSize="28sp"
android:textColor="#android:color/white"
android:layout_below="#+id/profile_img"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"/>
</RelativeLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/btn_change_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Change Password"
app:cornerRadius="50dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"/>
<Button
android:id="#+id/btn_sign_out"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign Out"
app:cornerRadius="50dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"/>
</LinearLayout>
</LinearLayout>
Here the image for preview
https://i.stack.imgur.com/QLaot.jpg
and here is the image for the emulator
https://i.stack.imgur.com/ED3FP.jpg
Different phones got different screen size, in your layout you are using fixed size on your view (fixed size is android:layout_width="100dp" for example) and the result is that what may look good on one screen (your android studio preview screen) will not look good on another screen (your actual phone).
If you want to create one layout to support all screen sizes you can use ConstraintLayout with guidelines and Chains to support different screen sizes.
Here is an example using ConstaintLayout:
<?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=".MainActivity">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent=".5" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/guideline7"
app:layout_constraintEnd_toStartOf="#+id/guideline9"
app:layout_constraintStart_toStartOf="#+id/guideline8"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars[1]" />
<TextView
android:id="#+id/textView9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Email"
app:layout_constraintEnd_toEndOf="#+id/imageView2"
app:layout_constraintStart_toStartOf="#+id/imageView2"
app:layout_constraintTop_toBottomOf="#+id/imageView2" />
<Button
android:id="#+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline9"
app:layout_constraintStart_toStartOf="#+id/guideline8"
app:layout_constraintTop_toTopOf="#+id/guideline7" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Button"
app:layout_constraintEnd_toStartOf="#+id/guideline9"
app:layout_constraintStart_toStartOf="#+id/guideline8"
app:layout_constraintTop_toBottomOf="#+id/button" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent=".1" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent=".9" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here is how it will look (I am attaching an image from the layout editor so you could see the constraints and guidelines):
You can use the tag android:layout_weight so that you don't have to worry about the different screen sizes. Here I made an example using android:layout_weight, android:layout_gravity and android:gravityfor making a structure you need. Hope it helps you. The screenshot of the structure is here.
You can get more reference about android:layout_weight from here.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/holo_blue_dark"
>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/profile_picture"
android:src="#drawable/user_profile_picture"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_picture"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="User Email"
android:textColor="#android:color/white"
android:textSize="28sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="#+id/btn_change_password"
android:layout_gravity="bottom"
android:text="change password"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="#+id/btn_sign_out"
android:layout_gravity="top"
android:text="sign out"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
You seem to be doing it right. I guess you just missed adding the weightSum in the parent tag.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_profile">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_img"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/default_person_icon"
app:civ_border_color="#android:color/black"
app:civ_border_width="2dp"
android:layout_centerInParent="true"
android:layout_marginTop="100dp" a/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Email"
android:textSize="28sp"
android:textColor="#android:color/white"
android:layout_below="#+id/profile_img"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"/>
</RelativeLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/btn_change_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Change Password"
app:cornerRadius="50dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"/>
<Button
android:id="#+id/btn_sign_out"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign Out"
app:cornerRadius="50dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"/>
</LinearLayout>
</LinearLayout>
This seemed to make it work for me. All the best!
Related
How can I make the Linear layout's background transparent?
I want to make the area around the share button transparent. I have tried various solutions like
android:background="#android:color/transparent"
and
android:alpha="0"
and many other solutions but none of these seems working.
How can I make this area transparent over the image and other elements?
I have also tried the Frame Layout but it also doesn't work.
Here is my XML code:
<?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"
android:theme="#style/Theme.MaterialComponents"
tools:context=".ReadMoreActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="100dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/readMoreImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/readMoreTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Card Title"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="30dp" />
<TextView
android:id="#+id/readMoreDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:paddingBottom="20dp"
android:text="Card description"
android:textAlignment="textStart"
android:textColor="#000000" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="-100dp"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="#+id/shareButton"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:text="Share"
android:textColor="#ffff"
android:textSize="25dp"
app:backgroundTint="#9C27B0"
app:strokeColor="#9C27B0"
app:strokeWidth="2dp" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
If I undestood You correclty You can do it like this:
<?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="match_parent"
android:theme="#style/Theme.MaterialComponents"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher_background"
/>
<TextView
android:id="#+id/readMoreTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Card Title"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="30sp"
/>
<TextView
android:id="#+id/readMoreDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="#string/long_card_desc"
android:textAlignment="textStart"
android:textColor="#000000"
>
</TextView>
</LinearLayout>
</ScrollView>
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:backgroundTint="#880E4F"
android:text="Share"
android:textColor="#FFF9C4"
app:cornerRadius="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:strokeColor="#006064"
app:strokeWidth="1dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Now Button sticks to the bottom of the screen and You can scroll the content.
Result (left with a scrolled view and right starter look):
Below is the image what I required.
You can see there is blue background and inside that, it has
Trailer Number 1 which is textview and 01010 is editext (input field)
Also outside the background, there is delete button near to the blu background.
What I tried is,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#color/app_white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/relative_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/blue_light"
android:layout_marginRight="60dp"
android:layout_marginLeft="60dp">
<TextViewÒ
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trailer number"
android:padding="#dimen/margin_5"
android:layout_margin="5dp"
android:layout_alignParentLeft="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:text="01010"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:layout_toRightOf="#+id/relative_1"
android:background="#drawable/ic_delete_cion" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
But delete icon is not at all displaying and also line is displaying in 01010 eddittext.
This is my screenshot.
I made some changes in ur layout and it is fit in ur requirement and fit for every device.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/relative_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/default_blue_light">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|start"
android:padding="10dp"
android:text="Trailer number" />
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:background="#null"
android:inputType="number"
android:padding="5dp"
android:text="01010"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/ic_delete_icon" />
</LinearLayout>
you can achive this by only putting android:weightSum into linear layout.
try below code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/app_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight=".9"
android:background="#color/blue_light"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:text="Trailer number" />
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:background="#null"
android:inputType="number"
android:text="01010"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_weight=".1"
android:layout_gravity="center"
android:background="#drawable/ic_delete_cion" />
</LinearLayout>
Try this xml code : (Please replace dimensions, padding, styles with your own)
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#FFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/relative_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:layout_weight="6"
android:background="#f5f5f5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="5dp"
android:gravity="center_vertical"
android:padding="5dp"
android:text="Trailer number" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:inputType="number"
android:text="01010" />
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:src="#drawable/ic_delete_black_24dp" />
</LinearLayout>
</LinearLayout>
I am working on an activity that has three recyclerviews.
My issue is that the output is different on different devices.
I am testing the app on my real device and on the Android Studio emulators, and the output is right. But I have some customers users who say that the output is wrong.
Here is my screen shot with the right output:
And this is the wrong output on some devices:
I have tried changing text size, but with no success.
I ask you where should I start looking for a solution, at recyclerview or at item view?
EDIT
Activity Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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="#f2f2f2">
<LinearLayout
android:id="#+id/cabeceraTicket"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/cardview_dark_background"
android:orientation="horizontal">
<TextView
android:id="#+id/txtTicket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Ticket: "
android:textColor="#color/cardview_light_background"
android:textSize="18sp" />
<TextView
android:id="#+id/txtSalon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Salón: "
android:textColor="#color/cardview_light_background"
android:textSize="18sp" />
<TextView
android:id="#+id/txtMesa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Mesa:"
android:textColor="#color/cardview_light_background"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/botones"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/cabeceraTicket"
android:orientation="horizontal">
<Button
android:id="#+id/btnTodo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Menu/Ticket" />
<Button
android:id="#+id/btnMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Menu" />
<Button
android:id="#+id/btnTicket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ticket" />
</LinearLayout>
<LinearLayout
android:id="#+id/botones2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/botones"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/btnRegresar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#009688"
android:text="Salir"
android:textColor="#color/white" />
<Button
android:id="#+id/btnMarchar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#3F51B5"
android:text="Marchar todo"
android:textColor="#color/white" />
</LinearLayout>
<Button
android:id="#+id/btnConectar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:visibility="gone" />
<LinearLayout
android:id="#+id/menus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/botones2"
android:orientation="vertical">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Menú"
android:textSize="24sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/lmenu1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/l0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="#android:drawable/ic_media_previous" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewMenu0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="10"
android:orientation="horizontal">
</android.support.v7.widget.RecyclerView>
<ImageView
android:id="#+id/r0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="#android:drawable/ic_media_next" />
</LinearLayout>
<LinearLayout
android:id="#+id/lmenu2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:id="#+id/l1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="#android:drawable/ic_media_previous" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewMenu1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="10"
android:orientation="horizontal">
</android.support.v7.widget.RecyclerView>
<ImageView
android:id="#+id/r1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="#android:drawable/ic_media_next" />
</LinearLayout>
<LinearLayout
android:id="#+id/lmenu3"
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:id="#+id/l2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="#android:drawable/ic_media_previous" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewArticulos1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="10"
android:orientation="horizontal">
</android.support.v7.widget.RecyclerView>
<ImageView
android:id="#+id/r2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="#android:drawable/ic_media_next" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ticket"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/menus"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/titulo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Ticket"
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/titulo"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:listSelector="#drawable/list_selector"
android:state_activated="true" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
First recyclerview item layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="1dp">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:cardCornerRadius="4dp"
app:cardElevation="1dp"
app:cardMaxElevation="2dp">
<RelativeLayout
android:id="#+id/relative"
android:layout_width="120dp"
android:layout_height="50dp"
android:gravity="center_horizontal|center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="4"
android:autoSizeMaxTextSize="15sp"
android:autoSizeMinTextSize="8sp"
android:autoSizeTextType="uniform"
android:gravity="center|center_horizontal|center_vertical"
android:padding="12dp"
android:text="Canada"
android:textAllCaps="false"
android:textColor="#color/red_A700"
android:textSize="30sp"
android:textStyle="bold"
app:autoSizeMinTextSize="20sp"
app:fontFamily="sans-serif" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
Second recyclerview item layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="1dp">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:cardCornerRadius="4dp"
app:cardElevation="1dp"
app:cardMaxElevation="2dp">
<RelativeLayout
android:id="#+id/relative"
android:layout_width="120dp"
android:layout_height="50dp"
android:gravity="center_horizontal|center_vertical">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:autoSizeMaxTextSize="15sp"
android:autoSizeMinTextSize="8sp"
android:autoSizeTextType="uniform"
android:gravity="center|center_horizontal|center_vertical"
android:padding="12dp"
android:text="Canada"
android:textAllCaps="false"
android:textColor="#color/red_A700"
android:textSize="30sp"
android:textStyle="bold"
app:autoSizeMinTextSize="20sp"
app:fontFamily="sans-serif" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
Third recyclerview item layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="1dp">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:cardCornerRadius="4dp"
app:cardElevation="1dp"
app:cardMaxElevation="2dp">
<RelativeLayout
android:id="#+id/relative"
android:layout_width="120dp"
android:layout_height="50dp"
android:gravity="center_horizontal|center_vertical">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:autoSizeMaxTextSize="15sp"
android:autoSizeMinTextSize="8sp"
android:autoSizeTextType="uniform"
android:gravity="center|center_horizontal|center_vertical"
android:padding="12dp"
android:text="Canada"
android:textAllCaps="false"
android:textColor="#color/red_A700"
android:textSize="30sp"
android:textStyle="bold"
app:autoSizeMinTextSize="20sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
your code contain like this,
<RelativeLayout
android:id="#+id/relative"
android:layout_width="120dp"
android:layout_height="50dp"
android:gravity="center_horizontal|center_vertical"></>
you need to change the item layout fixed length width
I would suggest not to set values for the textsize in your xml at all (either in dp or sp). Let each user choose their preferred textSize by changing the system-wide font size in the device's Settings--->Display--->FontSize.
Just make sure any container for these textViews (the parent layout of each textView) can accommodate textViews of varying sizes. One way this can be accomplished, is by setting the container's width and height values to 'WrapContent' if possible.
My answer should be viewed like a shift in your approach to text sizes in general, rather than a specific answer to a specific problem like the one you are facing. There may well be easier and faster solutions if you just want to quick-fix your current issue.
I have a RecyclerView inside a CardView but i have problem that i have 2 buttons in bottom of the RecyclerView so i put them at the end of RelativeLayout and give them parent_bottom true so i can make them visible but that makes the CardView have the full screen whether the RecyclerView have items of not.
Xml code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardElevation="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:padding="8dp">
<TextView
android:id="#+id/activeInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" Your active inspections"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rvActiveInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/btnClear"
android:layout_below="#+id/activeInspections"
android:layout_marginTop="8dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="8dp"
android:id="#+id/btnClear"
android:background="?selectableItemBackground"
android:text="CLear" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:id="#+id/btnContinue"
android:layout_alignParentBottom="true"
android:background="?selectableItemBackground"
android:text="Continue"
android:textColor="#color/blue_normal" />
</RelativeLayout>
</android.support.v7.widget.CardView>
And when i tried another thing the code below to make them below the RecyclerView so it fixed in case and the other case like shown (Buttons at the bottom not shown)
So how to fix this ?
<RelativeLayout 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="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardElevation="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:padding="8dp">
<TextView
android:id="#+id/activeInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" Your active inspections"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rvActiveInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/activeInspections"
android:layout_marginTop="8dp" />
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rvActiveInspections"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="?selectableItemBackground"
android:text="CLear" />
<Button
android:id="#+id/btnContinue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/rvActiveInspections"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="?selectableItemBackground"
android:text="Continue"
android:textColor="#color/blue_normal" />
</RelativeLayout>
</android.support.v7.widget.CardView>
the target one is this and when items expands it fit only the screen and don't go out of it
At first you can solve by changing your relativelayout inside CardView to LinearLayout and create nested relativelayouts for buttons. In order to avoid the nested layouts try my below code will help you..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardElevation="8dp">
<TextView
android:id="#+id/activeInspections"
android:layout_width="match_parent"
android:layout_height="25dp"
android:text=" Your active inspections"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rvActiveInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:layout_marginTop="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:id="#+id/btnClear"
android:layout_gravity="bottom"
android:background="?selectableItemBackground"
android:text="CLear" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:id="#+id/btnContinue"
android:layout_gravity="bottom|end"
android:background="?selectableItemBackground"
android:text="Continue"
android:textColor="#color/bb_darkBackgroundColor" />
</android.support.v7.widget.CardView>
</LinearLayout>
Adjust recylerview top and bottom margin according to your needs.
Just make the Recyclerview weight = 1 that means the parent should be LinearLayout
please check the code below
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardElevation="8dp">
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/activeInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text=" Your active inspections"
android:textSize="18sp"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvActiveInspections"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
/>
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:background="?selectableItemBackground"
android:text="CLear" />
<Button
android:id="#+id/btnContinue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:background="?selectableItemBackground"
android:text="Continue"
android:textColor="#color/blue_normal" />
</android.support.v7.widget.LinearLayoutCompat>
</android.support.v7.widget.LinearLayoutCompat>
</android.support.v7.widget.CardView>
Try changing the RelativeLayout inside the CardView with LinearLayout with vertical orientation.
Please Use Below Code. It's working Perfectly.
<RelativeLayout 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="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardElevation="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:padding="8dp">
<TextView
android:id="#+id/activeInspections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" Your active inspections"
android:textSize="18sp" />
<LinearLayout
android:id="#+id/bottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rvActiveInspections"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="?selectableItemBackground"
android:text="CLear" />
<Button
android:id="#+id/btnContinue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/rvActiveInspections"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:textColor="#color/blue_normal"
android:background="?selectableItemBackground"
android:text="Continue" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvActiveInspections"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottomLayout"
android:layout_below="#+id/activeInspections"
android:layout_marginTop="8dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
I have the following activity_main.xml file, and I want to align the three buttons inside the LinearLayout to the bottom of the page. I've tried layout_alignParentBotton="true"
but that doesn't work.. is there any setting that would let me bring the linearLayout to the bottom of the activity?
thanks
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blueBackground"
tools:context="org.pctechtips.george.dailyquotes.MainActivity">
<TextView
android:id="#+id/main_title"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:text="Daily Quotes"
android:textSize="30dp"
android:textColor="#color/whiteText"
android:textAlignment="center"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="16dp" />
<ImageView
android:id="#+id/main_image"
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="#mipmap/ic_launcher_round"
android:layout_centerHorizontal="true"
tools:layout_editor_absoluteY="89dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<TextView
android:id="#+id/quote_text"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:text="This is a random text"
android:textColor="#color/whiteText"
android:textSize="20dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="246dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<ImageView
android:id="#+id/previous_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/ic_media_previous"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="473dp" />
<ImageView
android:id="#+id/share_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="473dp" />
<ImageView
android:id="#+id/next_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/ic_media_next"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="473dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Change android:layout_alignParentBottom="true" to app:layout_constraintBottom_toBottomOf="parent". Here is an example that also stretches that layout to the width of the parent and centers the views within it
...
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
...
Add following Constraints to Your Linear layout .
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Some of your views are not constraints properly. If you want to use RelativeLayout then try the solution below .
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="#color/blueBackground"
tools:context="org.pctechtips.george.dailyquotes.MainActivity">
<TextView
android:id="#+id/main_title"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:text="Daily Quotes"
android:textSize="30dp"
android:textAlignment="center"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="16dp" />
<ImageView
android:id="#+id/main_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#+id/main_title"
app:srcCompat="#mipmap/ic_launcher_round"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/quote_text"
android:layout_width="match_parent"
android:layout_below="#+id/main_image"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerHorizontal="true"
android:text="This is a random text"
android:textSize="20dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true">
<ImageView
android:id="#+id/previous_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/ic_media_previous"
/>
<ImageView
android:id="#+id/share_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/next_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/ic_media_next"
/>
</LinearLayout>
</RelativeLayout>
Replace the parent constraint layout with a RelativeLayout
Try editing your layout this way:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="vertical" android:background="#color/blueBackground" tools:context="org.pctechtips.george.dailyquotes.MainActivity">
<LinearLayout android: layout_weight="1" android orientation="vertical" android:layout_width="match_parent" android:layout_height="0dp">
<TextView android:id="#+id/main_title" android:layout_width="368dp" android:layout_height="wrap_content" android:text="Daily Quotes" android:textSize="30dp" android:textColor="#color/whiteText" android:textAlignment="center" /> <ImageView android:id="#+id/main_image" android:layout_width="100dp" android:layout_height="100dp" app:srcCompat="#mipmap/ic_launcher_round" /> <TextView android:id="#+id/quote_text" android:layout_width="368dp" android:layout_height="wrap_content" android:text="This is a random text" android:textColor="#color/whiteText" android:textSize="20dp"/>
</LinearLayout>
<LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentBottom="true"> <ImageView android:id="#+id/previous_quote" android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="#android:drawable/ic_media_previous"/> <ImageView android:id="#+id/share_quote" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <ImageView android:id="#+id/next_quote" android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="#android:drawable/ic_media_next"/> </LinearLayout> </LinearLayout>
Note the layout weight in the Linear Layout.
Your root layout is a ConstraintLayout so you should position its children using the appropriate constraints listed in the documentation. In order to position the LinearLayout at the bottom center and wrap its content you should use the following:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
You can also optimize your layout by removing the LinearLayout altogether and constraining the three ImageViews in a horizontal chain as direct children of the root ConstraintLayout like this:
<ImageView
android:id="#+id/previous_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/ic_media_previous"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/share_quote"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/share_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/next_quote"
app:layout_constraintStart_toEndOf="#id/previous_quote"/>
<ImageView
android:id="#+id/next_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/ic_media_next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/share_quote" />
Try this..
<?xml version="1.0" encoding="utf-8"?><?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_blue_light">
<TextView
android:id="#+id/main_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Daily Quotes"
android:textAlignment="viewStart"
android:textColor="#android:color/white"
android:textSize="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/main_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="#mipmap/ic_launcher_round"
tools:layout_editor_absoluteY="89dp" />
<TextView
android:id="#+id/quote_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="This is a random text"
android:textColor="#android:color/white"
android:textSize="20dp"
app:layout_constraintTop_toBottomOf="#id/main_image" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="#+id/previous_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/ic_media_previous" />
<ImageView
android:id="#+id/share_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/next_quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/ic_media_next" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>