1
I’m trying to put 3 Imagebutton on a Linearlayout. The background image I’m using are drawable images that I added by clicking on the following sequence in Android Studio (2.2.2): Right-click on the drawable, new, vector Asset folder and choose which icon to add. After that I add in the activity_main.xml file a Linearlayout and inside it I add the 3 Imagebutton. In my Android Studio design it looks like this:
But when I run a test, whether on mobile or in the Android emulator itself, it is like this, the buttons do not appear. Only part of them is displayed:
Below follows the file acitivity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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:keepScreenOn="true"
android:background="@android:color/background_dark"
android:id="@+id/myMainActivity"
tools:context="com.example.root.dtvplayer.MainActivity">
<FrameLayout
android:id="@+id/video_surface_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:foregroundGravity="clip_horizontal|clip_vertical"
tools:ignore="true">
<SurfaceView
android:id="@+id/video_surface"
android:layout_width="1dp"
android:layout_height="1dp" />
<ViewStub
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/activity_subtitles_surface"
android:id="@+id/subtitles_stub" />
</FrameLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_expand_less_black_24dp"
android:id="@+id/imageButton24"
android:layout_weight="1" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_expand_more_black_24dp"
android:id="@+id/imageButton25"
android:layout_weight="1" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_youtube_searched_for_black_24dp"
android:id="@+id/imageButton26"
android:layout_weight="1" />
</LinearLayout>
Where I’m going wrong ?
HOW HE GOT THE SUGGESTED AMENDMENTS
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:keepScreenOn="true"
android:background="@android:color/background_dark"
android:id="@+id/myMainActivity"
tools:context="com.example.root.dtvplayer.MainActivity">
<FrameLayout
android:id="@+id/video_surface_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:foregroundGravity="clip_horizontal|clip_vertical"
tools:ignore="true">
<SurfaceView
android:id="@+id/video_surface"
android:layout_width="1dp"
android:layout_height="1dp" />
<ViewStub
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/activity_subtitles_surface"
android:id="@+id/subtitles_stub" />
</FrameLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:id="@+id/linearLayoutControls">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/arrow_up_float"
android:id="@+id/imgBtnUpChannel"
android:contentDescription="" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/arrow_down_float"
android:id="@+id/imgBtnDownChannel"
android:contentDescription="" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/ic_menu_search"
android:id="@+id/imgBtnSearchChannel"
android:contentDescription="" />
</LinearLayout>
</FrameLayout>
You’re putting the Imagebutton all in the same place, which means you’re superimposing one under the other. I believe this is looking at the xml code.
– Felipe Goncalves
I am placing the Imagebutton inside the same Linearlayout precisely so that they are not "encavalados" on each other. Linearlayout is in charge of distributing them equally. If I do exactly the same thing with Button buttons, this effect of cutting the component does not happen. It only happens with Imagebutton. See that in the designer of Android Studio the 3 buttons appear in full.
– Emerson
the Weight property if I’m not mistaken has to be defined in the linearLayout that Voce opened before imageButton, because Voce is using it in the image but is not defining what is the total weight of linearLayout. I’m not sure that’s clear.
– Felipe Goncalves
tries to put this property in the Linearlayout tag... android:weightSum="3"
– Felipe Goncalves
tried to put an android default image? for example @android/drawable/ic_menu_add or put a solid color.
– Danilo
I did what you suggested Felipe, but it did not work. It continued the same way.
– Emerson
tests with this feature of Imagebutton android:layout_gravity="right"
– Felipe Goncalves
takes a test. Instead of you setting Linear as wrap puts match and forehead
– Felipe Goncalves
If it doesn’t work Emerson uses Relativelayout.
– Felipe Goncalves
Yeah, with the match didn’t happen... I’ll try with Relativelayout
– Emerson