0

I saw this link and answer of bakwarte. Center two buttons horizontally

Toni Gamez said, This is for API >= 14.

I tried and saw that it works for level 10, for example. So could this be the right way for all API levels?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_margin="10dp">
        <Space
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1" />
        <ImageView
            android:id="@+id/imageView1"
            android:background="@drawable/Icon"
            android:layout_width="100dp"
            android:layout_height="wrap_content" />
        <Space
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1" />
    </LinearLayout>
</LinearLayout>
user2111639
  • 287
  • 2
  • 5
  • 15
  • ConstraintLayout is available as of API 9 you will get far better results using it. Constraining the image to the left and right of the screen and then setting the width to 100dp will do the same exact thing with less work. I can post an example as the answer if you want me too. – avalerio May 28 '21 at 16:57
  • @avalerio That is, without using space and regardless of the Android version, give the same result of space? – user2111639 May 28 '21 at 19:41

1 Answers1

1

Toni Gamez doesn't say why the answer is only for API >= 14, but it is probably because the Space widget was first introduced in API 14.

This technique will work for you on API 10, and other APIs, if you are picking up the Space widget from the support libraries or Androidx.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131