Hello everyone i am new to android development and i was trying to design an activity and i desgined it the way i wanted it to be but when i installed the apk in my phone the design is not same i check all the constraints and they are also right , here is the Images from both android studio and my mobile:-
Screen shot from mobile :-
Screenshot from android studio :-
Here is the layout 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"
tools:context=".Details_Page">
<ImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="234dp"
android:scaleType="fitXY"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/android_3" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout3"
android:layout_width="417dp"
android:layout_height="483dp"
android:background="@drawable/modern_bg_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.333"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
3
Answers
Install Device Info on your Android device. Then open it and locate the Display tab. There you will find your screen size in pixels like this: 1080×1920. Suppose if your screen size is 1080×2220, choose the device with the same size.
You can make layout folders for different density buckets. There are
Suppose if a device is xhdpi, so the layout with a xhdpi support will only scale on the xhdpi device.
So if you want to make different layout folders for different density buckets, right click on
res
folder and selectnew
and then Layout folder.Now choose Density buckets from the list and select the last Density bucket.
Keep doing this until you have all the layout folders for density buckets.
Then choose the device for the layout. Suppose I am in file for a xhdpi device so in layout editor choose a xhdpi device. Do this for all layout files..
Then design different layouts for different density buckets.
I hope it may help you.
Please edit the answer if english is not good
Thanks
As Alexander has commented, your UI need to be scalable, you need to create relative constraint between views so that it can scale properly in different displays.
First, you should remove
app:layout_constraintHorizontal_bias="0.333"
andapp:layout_constraintVertical_bias="1.0"
as they either don’t work in this context or scale differently in different screen size.Next, since your image has a fixed height, an easy way to achieve what you want is to use
margin_top
. You will have to find out the exact value yourself in order to make the curvy background hide a part of your image. Here is some example, I set themargin_top
temporarily as 200dp :could use RelativeLayout: