Inflating another layout with drawer layout - java

Greetings my fellow programmers,
I've got an easy one i'd guess but i still don't know why it causes such behaviour.
So the scene is this: i've got appliaction which plays music via service and the mini player at the bottom which i've added in a way that i inflated main layout.
If i do not inflate layout with the mini player i can use method's (menu items) inside drawer normally (it takes me to wanted destination and triggers sliding operations flawlessly) once i start playing music i infalte the layout so i show the player and i can do this with drawer :
I can open it from sliding and from hamburger button
I can open it from sliding and from hamburger button
I CAN'T CLOSE it by right-left slide
METHODS DO NOT work inside drawer
Any ideas why inflating messes it up?
P.S
On the main layout i use Coordinator Layout at parent view so i can use floating buttons
***** EDIT: HERE ARE SCREENS ******
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/cili_test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.android.listenyo_41.MainActivity"
android:background="#color/white">
<!-- Loading indicator is only shown before the first load -->
<RelativeLayout 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"
tools:context="com.example.android.listenyo_41.MainActivity"
android:id="#+id/cili_test2"
android:background="#color/black"
>
<!-- Loading indicator is only shown before the first load -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/nesto_glupo"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/black">
<ImageButton
/>
<android.support.v7.widget.Toolbar
/>
<com.miguelcatalan.materialsearchview.MaterialSearchView
/>
</RelativeLayout>
<ListView
/>
<RelativeLayout
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:background="#color/black"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:id="#+id/test_fade"
>
<Button
/>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
/>
</android.support.v4.widget.SwipeRefreshLayout>
<!-- Empty view is only visible when the list has no items. -->
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<TextView
/>
<ProgressBar
/>
</RelativeLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/drawer_view"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#color/white"
android:background="#color/black"
app:itemTextColor="#color/white"
/>
</android.support.v4.widget.DrawerLayout>
<ProgressBar
android:id="#+id/picasso_progress"
style="#android:style/Widget.Holo.Light.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:visibility="gone" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#75d9534f"
android:id="#+id/crvena_traka"
>
<RelativeLayout
android:id="#+id/songName_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<SeekBar
android:id="#+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="135dp"
android:layout_marginTop="5dp"
android:paddingEnd="6dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingStart="6dp"
android:progressDrawable="#drawable/progress_drawable"
android:thumbTint="#color/black"
android:visibility="gone"
/>
<TextView
android:id="#+id/songDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/seekBar"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="140dp"
android:layout_marginTop="2dp"
android:text="00:00:00"
android:textColor="#color/white"
android:textStyle="bold"
android:visibility="gone"
/>
<com.example.android.listenyo_41.ScrollTextView
android:id="#+id/songName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/seekBar"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_toLeftOf="#id/songDuration"
android:textColor="#color/white"
android:textSize="14sp"
android:textStyle="bold"
android:visibility="gone"
/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<TextView
android:id="#+id/btn_lay_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:text="Buffering"
android:textAlignment="center"
android:textColor="#color/gray"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="gone"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#id/player_controler"
android:layout_weight="2">
<ProgressBar
android:id="#+id/loading_indicator2"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:indeterminateDrawable="#drawable/my_border4"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/player_controler2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#color/black"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_marginTop="20dp"
android:orientation="vertical"
>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:choiceMode="singleChoice"
android:divider="#null"
android:dividerHeight="5dp"
android:orientation="horizontal"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/activity_main_swipe_refresh_layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:visibility="gone">
<TextView
android:id="#+id/empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:gravity="center"
android:textAppearance="?android:textAppearanceMedium"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/drawer_view"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#color/white"
android:background="#color/black"
app:itemTextColor="#color/white"
/>
</android.support.v4.widget.DrawerLayout>
</android.support.design.widget.CoordinatorLayout>
And the mini player
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:id="#+id/play_test"
android:visibility="visible"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="#color/myColor"
android:elevation="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="5dp"
android:id="#+id/play_lay"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:background="#drawable/bl_tran_grad"
>
<RelativeLayout
android:id="#+id/icon_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:onClick="player"
>
<ProgressBar
style="#android:style/Widget.Holo.Light.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:visibility="gone"
android:id="#+id/picasso_progress2"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_gravity="center"
android:id="#+id/error2"
android:text="Error loading picture"
android:textColor="#color/black"
android:textSize="13sp"
android:textStyle="bold"
android:textAlignment="center"
android:layout_centerInParent="true"
/>
<ImageView
android:id="#+id/player_img"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:scaleType="centerCrop"
>
</ImageView>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:layout_margin="5dp"
android:onClick="player"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:id="#+id/songName2"
android:textSize="14sp"
android:layout_centerVertical="true"
android:textColor="#color/white"
android:textStyle="bold"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="player_2_pause"
>
<ImageView
android:layout_width="50dp"
android:layout_height="35dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_launcher"
android:onClick="player_2_resume"
android:visibility="invisible"
android:id="#+id/player_2_resume"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buffering"
android:textColor="#color/white"
android:layout_centerInParent="true"
android:textSize="14sp"
android:visibility="visible"
android:id="#+id/buffering"
/>
<ImageView
android:layout_width="50dp"
android:layout_height="35dp"
android:src="#drawable/pause2"
android:onClick="player_2_pause"
android:visibility="invisible"
android:id="#+id/player_2_pause"
android:layout_centerInParent="true"
/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<SeekBar
android:padding="0dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/seekBar_player2"
android:layout_width="match_parent"
android:layout_height="4.0dp"
android:layout_above="#id/play_lay"
android:background="#80000000"
android:maxHeight="5dp"
android:minHeight="4dp"
android:progressDrawable="#drawable/progress_drawable"
android:max="10"
android:thumb="#color/white"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp" />
</RelativeLayout>
When player active[1]
without player drawer[2]
both[3]
[1]: https://i.stack.imgur.com/gD0BY.jpg
[2]: https://i.stack.imgur.com/0zcYP.jpg
[3]: https://i.stack.imgur.com/qFY6q.jpg

Related

Toolbar back arrow with icon

How to display icon with back arrow in android toolbar like WhatsApp ?
I would like to reduce the space between the photo and the back arrow.
How can I reduce space?
I have:
ChatActivity.java: the layout (which has only one view) is replaced with ChatFragment.java. Moreover, the toolbar is replaced here with fragment_chat_toolbar.xml
ChatFragment.java: here the inputs, the emojis, the files etc. are managed
Thanks.
My toolbar chat
fragment_chat.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/layout_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="#+id/fragment_chat_recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:gravity="center" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginEnd="4dp"
android:background="#drawable/incoming_message"
android:baselineAligned="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="2dp"
android:paddingStart="2dp"
android:paddingEnd="4dp" >
<ImageView
android:id="#+id/image_view_emoji"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginStart="6dp"
android:layout_gravity="center"
android:contentDescription="#string/emoji_button"
android:src="#mipmap/ic_emoji"
android:tint="#color/total_black" />
<com.vanniktech.emoji.EmojiEditText
android:id="#+id/message_box_emoji"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
android:layout_weight="1"
android:background="#color/incomingColor"
android:hint="#string/send_message"
app:emojiSize="26sp"/>
<ImageView
android:id="#+id/image_view_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:layout_gravity="center"
android:contentDescription="#string/camera_button"
android:src="#mipmap/ic_camera"
android:tint="#color/total_black" />
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/float_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="#mipmap/ic_voice_recorder"
android:tint="#color/white"
app:backgroundTint="#color/colorPrimary"
app:elevation="0dp"
app:fabSize="mini"/>
</LinearLayout>
</LinearLayout>
fragment_chat_toolbar.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:clipChildren="false" >
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/profile_photo"
android:layout_width="50dp"
android:layout_height="50dp"
fresco:failureImage="#drawable/default_profile"
fresco:placeholderImage="#drawable/default_profile"
fresco:roundAsCircle="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="4dp"
android:gravity="start"
android:orientation="vertical" >
<TextView
android:id="#+id/chat_title_text_view"
android:layout_width="wrap_content"
android:textSize="16sp"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="#color/white" />
<TextView
android:id="#+id/chat_subtitle_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="#color/white" />
</LinearLayout>
Make Custom Toolbar as you like. Change your layout in RelativeLayout
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/llLeft"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/transparent_layout_background"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:padding="10dp">
<ImageView
android:id="#+id/ivLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_action_menu" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="#+id/llLeft"
android:layout_toLeftOf="#+id/llRight"
android:layout_toRightOf="#+id/llLeft"
android:layout_toStartOf="#+id/llRight"
android:gravity="center">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="#font/roboto_bold"
android:lines="1"
android:text="asdf"
android:textColor="#color/colorWhite"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/llRight"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="#drawable/transparent_layout_background"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:padding="10dp">
<ImageView
android:id="#+id/ivRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_action_search" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>

Progress bar height

I try to integrate progress bar in my layout. The progress bar cannot fix all screen size. I try to tune the height many times. But no one is suitable for every device. So how can I fix the progress bar height in all screen size.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="#drawable/gray_bg"
android:orientation="vertical">
<ImageView
android:id="#+id/bg_pushup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.7"
android:background="#android:color/background_dark"
android:src="#drawable/image_push_up"
android:visibility="gone" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/counter_button_close" />
<ImageView
android:id="#+id/btn_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/counter_button_mute" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/txt_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="START PUSH-UPS"
android:textColor="#android:color/background_light" />
<RelativeLayout
android:id="#+id/layout_pushup"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_start"
android:layout_centerInParent="true"
android:src="#drawable/counter_bg"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<TextView
android:id="#+id/txt_pushup_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="0"
android:textAlignment="center"
android:textColor="#android:color/background_light"
android:textSize="36sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_pushup_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="false"
android:layout_centerVertical="false"
android:layout_gravity="center_horizontal"
android:text="0:00"
android:textAlignment="center"
android:textColor="#b5b4ad"
android:textSize="30sp" />
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:max="100"
android:progress="75"
android:progressDrawable="#drawable/style_circular"
android:secondaryProgress="100" />
<TextView
android:id="#+id/textView19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/progressBar2"
android:layout_alignBottom="#+id/progressBar2"
android:layout_centerHorizontal="true"
android:text="TextView"
android:textAlignment="center" />
<ImageView
android:id="#+id/img_shade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView19"
android:layout_centerHorizontal="true"
android:layout_centerInParent="false"
android:layout_weight="0.05"
android:src="#drawable/counter_shade" />
<ImageView
android:id="#+id/btn_question_mark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/progressBar2"
android:layout_alignParentEnd="true"
android:layout_weight="1"
android:src="#drawable/question_mark" />
</RelativeLayout>
Progress bar
Please help me to design the xml for all screen size device.
putting the progress bar inside a container and then doing the size will work fine! try like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight = 1>
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:max="100"
android:progress="75"
android:progressDrawable="#drawable/style_circular"
android:secondaryProgress="100" />
</LinearLayout>

how to center invisible Button

i'm trying to make (try again) button in center this button is invisible , i already tried to put : android:layout_gravity="center"
but doesn't work any suggestions for resolve this problems
This what he give me :
My XML file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffff"
android:id="#+id/activity_viewsol">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Light"
android:fitsSystemWindows="true"
app:layout_collapseMode="pin"
android:elevation="5dp"
app:navigationIcon="#drawable/ic_back"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="48sp"
android:textStyle="bold"
android:text="Solution"
android:id="#+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:id="#+id/scrollview"
android:stackFromBottom="true"
android:scrollbarSize="10dp"
android:scrollbarThumbVertical="#drawable/scrollbar"
android:transcriptMode="alwaysScroll">
<LinearLayout
android:id="#+id/All_Layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="6dp"
android:padding="15dp">
<TextView
android:typeface="normal"
android:layout_gravity="center"
android:id="#+id/prob"
android:textStyle="bold"
android:textColor="#383838"
android:gravity="center"
android:textSize="45sp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginBottom="20dp">
<View
android:layout_height="1dp"
android:layout_width="500dp"
android:background="#000"
android:layout_gravity="center"/>
<TextView
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="O"
android:textSize="40sp"
android:textColor="#color/colorAccent"
android:textStyle="bold"
android:layout_gravity="center"/>
<View
android:layout_height="1dp"
android:layout_width="500dp"
android:background="#000"
android:layout_gravity="center" />
</LinearLayout>
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="35sp"
android:textStyle="normal"
android:textColor="#383838"
android:id="#+id/sol"
android:typeface="normal"
android:layout_marginBottom="20dp"/>
<View
android:id="#+id/LineHorizontalTwo"
android:layout_height="1dp"
android:layout_width="1000dp"
android:background="#000"
android:layout_gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:layout_margin="20dp"
android:layout_gravity="start|center"
android:id="#+id/Like"
android:src="#mipmap/ic_like"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:layout_margin="20dp"
android:layout_gravity="end|center"
android:id="#+id/sharesol"
android:src="#mipmap/ic_action_share"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#mipmap/retry"
android:drawablePadding="10dp"
android:layout_gravity="center"
android:gravity="center"
android:visibility="gone"
android:id="#+id/retry"
android:onClick="onClickRetry"
android:background="#null"
android:padding="6dp"
android:textSize="35sp"
android:text="TRY AGAIN"
android:textColor="#000" />
</LinearLayout>
You can do it simply doing by enclosing your error button inside the Relative Layout as following steps:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:id="#+id/retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:drawablePadding="10dp"
android:drawableTop="#drawable/ic_android"
android:gravity="center"
android:padding="6dp"
android:text="TRY AGAIN"
android:textColor="#000"
android:textSize="35sp"
android:visibility="visible" />
</RelativeLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
also you need a RelativeLayout for parent of this tag
Make the parent layout as RelativeLayout and put everything inside RelativeLayout except the button.
use
<RelativeLayout 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">
<!--Put your other codes here-->
<!--everything can be within LinerarLayout-->
<Button
android:id="#+id/retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#null"
android:drawablePadding="10dp"
android:drawableTop="#mipmap/retry"
android:onClick="onClickRetry"
android:padding="6dp"
android:text="TRY AGAIN"
android:textColor="#000"
android:textSize="35sp"
android:visibility="gone" />
</RelativeLayout>
as your button code

Views shrink when using keyboard with PercentageLayout

i have 2 different XML files. One is signup.xml the other chat.xml, both constructed with the PercentageLayout library.
the signup.xml works great - opening keyboard doesnt change any view.
However, in chat.xml whenever i pop the keyboard the view shrinks or out of screen, and i dont know why since i constructed them both nearly in the same manner, only i suspect that because i use ScrollView this happens.
The problematic layout, chat.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- top -->
<LinearLayout
android:id="#+id/top"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="8%"
android:background="#075607"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#acddf4"
android:textSize="20sp"
android:text="jfioewjfoiewjfoi"
android:gravity="center"
android:layout_gravity="center_horizontal|center_vertical" />
</LinearLayout>
<!-- Mid -->
<LinearLayout
android:id="#+id/mid"
android:layout_below="#+id/top"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="84%"
android:background="#b1b7b3"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroller"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#drawable/chat_bg" >
<LinearLayout
android:id="#+id/chatWindowContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
<!-- Bottom -->
<LinearLayout
android:id="#+id/bottom"
android:layout_below="#+id/mid"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="100%"
app:layout_heightPercent="8%"
android:background="#000000"
android:orientation="horizontal">
<EditText
android:id="#+id/etMessage"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:paddingLeft="5dp"
android:background="#drawable/text"
android:imeOptions="actionNone"
android:inputType="textMultiLine"
android:singleLine="false" />
<Button
android:id="#+id/bSendMessage"
android:layout_width="40dp"
android:layout_height="match_parent"
android:background="#drawable/ic_send"
android:layout_gravity="right" />
</LinearLayout>
And the working layout, signup.xml :
<LinearLayout
android:id="#+id/title"
android:layout_height="0dp"
android:layout_width="0dp"
app:layout_heightPercent="15%"
app:layout_widthPercent="100%">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/signup"/>
</LinearLayout>
<LinearLayout
android:id="#+id/mid"
android:orientation="vertical"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_below="#+id/title"
app:layout_heightPercent="35%"
app:layout_widthPercent="100%"
android:baselineAligned="true">
<!-- Username -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="#drawable/person" />
<EditText
android:id="#+id/etUsername_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="text"
android:text="test"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="#drawable/text">
<requestFocus />
</EditText>
</LinearLayout>
<!-- Email -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="#drawable/email" />
<EditText
android:id="#+id/etEmail_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textEmailAddress"
android:text="email#address.com"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="#drawable/text"/>
</LinearLayout>
<!-- Password1 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="#drawable/password" />
<EditText
android:id="#+id/etPassword1_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textPassword"
android:text="pass"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="#drawable/text"/>
</LinearLayout>
<!-- Password2 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%">
<ImageView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:src="#drawable/password" />
<EditText
android:id="#+id/etPassword2_signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:ems="10"
android:inputType="textPassword"
android:text="pass"
android:textColor="#000000"
android:paddingLeft="5dp"
android:layout_weight="0.1"
android:background="#drawable/text"/>
</LinearLayout>
<!-- Spinner and RadioGroup-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Spinner
android:layout_width="100dp"
android:layout_height="match_parent"
android:id="#+id/spinner"
android:layout_gravity="center" />
<RadioGroup
android:id="#+id/rgRadius"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Kilometer" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mile" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
<!-- Image -->
<LinearLayout
android:id="#+id/image"
android:orientation="vertical"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_below="#+id/mid"
app:layout_heightPercent="40%"
app:layout_widthPercent="100%"
android:baselineAligned="true">
<ImageView
android:id="#+id/imgProfile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/faceless" />
</LinearLayout>
<!-- Button -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="10%"
app:layout_widthPercent="100%"
android:orientation="vertical"
android:layout_below="#id/image">
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="#+id/bSignup"
android:layout_gravity="center|bottom"
android:background="#drawable/button_send" />
</LinearLayout>
Use relative layout solve your shrinking layout problem I tested following layout.
Add following entry with activity tag : android:windowSoftInputMode="adjustResize"
And Your layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- top -->
<LinearLayout
android:id="#+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#075607"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#acddf4"
android:textSize="20sp"
android:text="jfioewjfoiewjfoi"
android:gravity="center"
android:layout_gravity="center_horizontal|center_vertical" />
</LinearLayout>
<!-- Mid -->
<LinearLayout
android:id="#+id/mid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom"
android:layout_below="#+id/top"
android:background="#b1b7b3"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroller"
android:layout_width="match_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/chatWindowContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
<!-- Bottom -->
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/etMessage"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:paddingLeft="5dp"
android:imeOptions="actionNone"
android:inputType="textMultiLine"
android:singleLine="false" />
<Button
android:id="#+id/bSendMessage"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_gravity="right" />
</LinearLayout>
</RelativeLayout>

Android layout inconsistency

I have a layout that is being displayed in two different layouts. First one is being displayed in a LinearLayout and it behaves as expected:
However, when this layout is part of a listview, the textview is not centered:
Here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="130dp"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:padding="5dp">
<com.parse.ParseImageView
android:id="#+id/iv"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitCenter"/>
<TextView
android:id="#+id/tv_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.5"
android:layout_marginLeft="10dp"
android:textAppearance="#android:style/TextAppearance.Holo.Medium"
android:ellipsize="end"
android:maxLines="3"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:orientation="horizontal"
android:paddingLeft="10dp">
<View
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/blue"
android:layout_gravity="center"
/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<TextView
android:id="#+id/tv_source"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAppearance="#android:style/TextAppearance.Holo.Small"
android:gravity="center"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<TextView
android:id="#+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="sans-serif-light"
android:textAppearance="#android:style/TextAppearance.Small"
android:gravity="center"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_fire"
android:layout_gravity="center"/>
<TextView
android:id="#+id/tv_viewCount"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="sans-serif-light"
android:textAppearance="#android:style/TextAppearance.Small"
android:gravity="center"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"/>
</LinearLayout>
<ImageView
android:id="#+id/pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_pin"/>
<TextView
android:id="#+id/comment_tv"
android:layout_width="0dp"
android:layout_height="0dp"
android:textColor="#color/white"
android:layout_alignTop="#+id/pin"
android:layout_alignBottom="#+id/pin"
android:layout_alignLeft="#id/pin"
android:layout_alignRight="#+id/pin"
android:gravity="center"
android:layout_marginBottom="10dp"/>
</RelativeLayout>
The textView that I am referring to is at the bottom with id comment_tv
What am I doing wrong?
Thanks
Your pin+text inside a relative layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_gravity="center_vertical" >
<ImageView
android:id="#+id/pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_pin"/>
<TextView
android:id="#+id/comment_tv"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#id/pin"
android:gravity="center"
android:layout_marginTop="10dp" //set this higher if you need
android:layout_centerHorizontal="true" //if this text will be not in the center
//you can use the "layout_marginLeft" to put whatever you want
/>
</RelativeLayout>
This should but the text on the spot you want
I tried it with your image and this is my result with underlying code. Is this what you are looking for?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/sample"
android:gravity="center"
android:text="12"
android:textSize="18sp" />
</LinearLayout>
And heres a snapshot of this code:

Categories