Issue
I'm having stupid issues with a LinearLayout. I'm requesting the NO_TITLE feature before the setContentView and I have a Xaml looking like this :
<LinearLayout
android:baselineAligned="false"
android:orientation="vertical"
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"
android:background="#E600323d"
tools:context="mycontext.Activities.dialogSignal"
android:layout_alignParentBottom="true"
android:gravity="center"
>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="SOME TEXT"
android:textAlignment="center"
android:textColor="@color/LightBlue"
android:textSize="30sp"
app:layout_heightPercent="10%"/>
<!-- FIRST ROW -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
>
<ImageButton
android:onClick="bruitNavigate"
android:src="@drawable/someDrawable"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="@string/descriptionContentSignal"
android:layout_width="match_parent"
android:layout_height="90dp"/>
<TextView
android:paddingTop="10dp"
android:text="@string/SomeString"
android:textSize="15sp"
android:textAlignment="center"
android:textColor="@color/LightBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
>
<ImageButton
android:src="@drawable/someDrawable"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="@string/descriptionContentSignal"
android:layout_width="match_parent"
android:layout_height="90dp"/>
<TextView
android:paddingTop="10dp"
android:text="SomeString"
android:textSize="15sp"
android:textAlignment="center"
android:textColor="@color/LightBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
>
<ImageButton
android:src="@drawable/someDrawable"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="@string/descriptionContentSignal"
android:layout_width="match_parent"
android:layout_height="90dp"/>
<TextView
android:paddingTop="10dp"
android:text="@string/SomeString"
android:textSize="15sp"
android:textAlignment="center"
android:textColor="@color/LightBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<!-- SECOND ROW -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
>
<ImageButton
android:src="@drawable/someDrawable"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="@string/descriptionContentSignal"
android:layout_width="match_parent"
android:layout_height="90dp"/>
<TextView
android:paddingTop="10dp"
android:text="SomeString"
android:textSize="15sp"
android:textAlignment="center"
android:textColor="@color/LightBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
>
<ImageButton
android:src="@drawable/someDrawable"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="@string/descriptionContentSignal"
android:layout_width="match_parent"
android:layout_height="90dp"/>
<TextView
android:paddingTop="10dp"
android:text="SomeString"
android:textSize="15sp"
android:textAlignment="center"
android:textColor="@color/LightBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
>
<ImageButton
android:src="@drawable/someDrawable"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="@string/descriptionContentSignal"
android:layout_width="match_parent"
android:layout_height="90dp"/>
<TextView
android:paddingTop="10dp"
android:text="@string/SomeString"
android:textSize="15sp"
android:textAlignment="center"
android:textColor="@color/LightBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<!-- THIRD ROW -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
>
<ImageButton
android:src="@drawable/someDrawable"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="@string/descriptionContentSignal"
android:layout_width="match_parent"
android:layout_height="90dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="@string/SomeString"
android:textAlignment="center"
android:textColor="@color/LightBlue"
android:textSize="15sp"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
>
<ImageButton
android:src="@drawable/someDrawable"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:contentDescription="@string/descriptionContentSignal"
android:layout_width="match_parent"
android:layout_height="90dp"/>
<TextView
android:paddingTop="10dp"
android:text="SomeString"
android:textSize="15sp"
android:textAlignment="center"
android:textColor="@color/LightBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:gravity="center"
>
<ImageButton
android:id="@+id/imageButton"
android:layout_width="150dp"
android:layout_height="85dp"
android:layout_gravity="bottom|center"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/centralbutton"/>
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:background="@android:color/transparent"
android:contentDescription="@string/accept"
android:onClick="closeView"
android:scaleType="fitCenter"
android:src="@drawable/cancel"
/>
</LinearLayout>
</LinearLayout>
So, the last LinearLayout (the one containing only two ImageButtons) does not align with the bottom of the screen and is floating somewhere depending of the screen size.
I'm applying this style to get a transparent background :
<style name="dialogStyle" parent="@android:style/Theme.Holo">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
If anyone has met the same issue, I would love to get ideas... Thank you for your time !
Solution
Try this for your last Linearlayout
Make the Height to match parent
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:baselineAligned="false"
android:gravity="center">
</LinearLayout>
OR
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1" //add this
android:baselineAligned="false"
android:gravity="center">
Explanation:
All the items inside this LinearLayout
take some space, make sure that the last item, which is the LinearLayout
wrapping the buttons, stretches to occupy all the remaining space. Set android:layout_weight="1"
or make the height match_parent
Answered By - rafsanahmad007
Answer Checked By - Clifford M. (JavaFixing Volunteer)