i try to create a Android-App that using all images from gitHub png-images 0ad.
i try to put all (about 19) images at the screen. i tried to set the image size to 17% of the screen (or 0.17).
if i set all to layout_width="match_parent"
images are to large.
if i set images to layout_width="50dp"
images are to small for some devices.
my idea was to use (because i have read android.com..multiscreen
resources.displayMetrics * 0.10
as image size.
I also tried many answers from Percentage width in a RelativeLayout. Seems outdated.
full source: https://github.com/0ad-matters/0ad-counter-unit-guide
My best Solution in app/src/main/res/layout/activity_main.xml
at the moment
shows images to small:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:minWidth="match_parent"
android:minHeight="match_parent"
android:maxWidth="match_parent"
android:maxHeight="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow android:layout_width="match_parent" android:layout_height="match_parent">
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/emblem_athenians"
style="@style/Widget.AppCompat.ImageButton"/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/emblem_britons"
/>
</TableRow>
</TableLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
TabkeRow match_parent for layout_width and layout_height looks like this:
if i use wrap_content
for with of a image it takes 100% of the image size. thats to large as you could see here: