this is my xml code i want to set two images in row
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:padding="10dp"
android:background="#ffffff"
tools:context=".SplashActivity">
<ImageView
android:layout_width="340dp"
android:layout_height="340dp"
android:layout_gravity="left"
android:src="@drawable/ic_2"
android:text="Hello World!"
android:tint="#ff0000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.498"
tools:layout_editor_absoluteX="-52dp" />
<ImageView
android:layout_width="340dp"
android:layout_height="340dp"
android:layout_gravity="right"
android:src="@drawable/ic_karo"
android:text="Hello World!"
android:tint="#0000b3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.498"
tools:layout_editor_absoluteX="123dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
In Android Studio Preview, It’s looking perfect as I want. But when I install APK in a device, It’s not working
Android Studio Preview:
This is my Device Preview:
4
Answers
You should use a Linera Layout instead Constraint Layout or Linear Leyout within parent Constraint Layout. You can directly use the following code:
As I mentioned in the comment add layout_gravity as centre in both the ImageView. I have also edited the code as you can not use text in Image View.
Hope this will work perfectly for you.
i think you should try with Linear Layout
Like this…
As I can see your question you can use Constraint layout property to set two images in row :-
Start to Start
End to End
Start to End
End to Start
for example :-