Reputation: 297
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>
Upvotes: 0
Views: 35
Reputation: 62831
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.
Upvotes: 1