How to make 2 horizontal buttons to fill relative layout equally? - android-relativelayout

the corresponding xml layout:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttons_holder"
android:layout_below="#+id/list_holder"
android:layout_alignParentBottom="true">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/previous_button"
android:src="#android:drawable/ic_media_previous"
android:layout_alignParentLeft="true"
android:minWidth="150dp"
android:layout_alignParentBottom="false"
android:layout_alignParentRight="false"
android:layout_alignParentTop="false"
android:scaleType="fitEnd" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/forward_button"
android:src="#android:drawable/ic_media_next"
android:layout_alignParentRight="true"
android:minWidth="150dp"
android:scaleType="fitStart"
android:layout_alignWithParentIfMissing="false" />
</RelativeLayout>
I can change button's width just by setting
minWidth = 200dp
maxWidth = 200dp
so the button will occupy fixed space inside my relative layout
but i want to do it the 'right way' - using probably gravity, but there is no gravity for button - only for my relative layout that holds these 2 buttons
How to properly make 2 buttons occupy equal space inside rel layout?

you can use #Onik's suggestion. If you want to use RelativeLayout only then
Place dummy view in center of RelativeLayout
Put button1 toLeft of dummy view
Put button2 toRight of dummy view
Sample Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/dummy" />
<View
android:id="#+id/dummy"
android:layout_width="1dp"
android:layout_height="1dp"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/dummy" />
</RelativeLayout>

Related

Button doesn't show on top of Maps Activity

I'm trying to add a button on top of Map Activity, in the layout.
I just want to show a button over the map layout, but I tried different layouts, Constraint, Relative... and nothing works. I also tried to put the map fragment in XML before and after the button inside a relative layout, and yet it did nothing, it shows only the map.
I resized the map and even removed the map layout, and still the map shows in full screen.
<android.support.constraint.ConstraintLayout
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/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="#+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="270dp"
android:layout_height="336dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context="com.parse.starter.RidersActivity" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
You don't need to say the orientation for constraintLayout. Just make your fragment sizes android:layout_width="match_parent" and
android:layout_height="match_parent" , add button and constraint it to your fragment:
You don't need to say the orientation for constraintLayout. Just make your fragment sizes android:layout_width="match_parent" and
android:layout_height="match_parent" , add button and constraint it to your fragment:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
It looks like this :
Just Make your Fragment height and weight attribute match_parent
Try below code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="160dp"
android:layout_marginBottom="652dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
I hope its work for you
i finally found the problem, i accidentally created 2 similar activities and i was editing the wrong activity, that's why there were no errors. Thanks everybody who tried to help.

How to add FloatingActionButton on maps in xamarin.android

I am trying to add custom button for locate me for the maps. I came to know we need to use FloatingActionButton, so I have created as following in my layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/header">
<include
android:id="#+id/mapToolbar"
layout="#layout/toolbar" />
</RelativeLayout>
<Spinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/maptype_arrays" />
<fragment
android.id="#+id/map"
android:tag="maptag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:src="#drawable/locateme_icon"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</LinearLayout>
But Im not getting button on the screen when run this. Is there anything to add along with this.
Thanks in advance.
I got the FloatingActionButton displayed by changing Linear layout to Frame layout.

Is it possible to pause the auto changing image in view flipper with a touch

Is it possible to pause the auto changing image with a finger touch in view flipper. Here I have given a product 360 view with some images , now I want to give the users a facility to pause and see the image .
Below given is the current XML
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_kten_seeround"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".KtenSeeround">
<ViewFlipper
android:id="#+id/flipper1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:autoStart="true"
android:flipInterval="500"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/image1"
android:src="#drawable/kten75"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/image2"
android:src="#drawable/kten70"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/image3"
android:src="#drawable/kten65"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/image4"
android:src="#drawable/kten60"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/image5"
android:src="#drawable/kten55"/>
</ViewFlipper>
</RelativeLayout>

Collapse Toolbar affects other layout

I have this layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleGravity="center_vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="center"
android:theme="#style/Base.ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"
app:titleMarginStart="35dp"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax">
<Button
android:id="#+id/go_to_deezer_btn"
android:layout_width="135dp"
android:layout_height="36dp"
android:layout_gravity="bottom|center"
android:layout_marginBottom="52dp"
android:background="#drawable/rounded_corners_button"
android:text="#string/go_to_deezer"
android:textSize="12sp"
app:layout_anchor="#id/header"
app:layout_anchorGravity="bottom|center_horizontal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.cmd.cienradios.ui.header.EntityHeaderAlbum
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="#+id/deezer_banner"
layout="#layout/deezer_banner"
android:layout_width="match_parent"
android:layout_height="70dp" />
</LinearLayout>
</FrameLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout_generic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:theme="#style/Theme.AppCompat.NoActionBar"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.AppCompat.NoActionBar"
>
<com.cmd.cienradios.ui.TrackRecyclerView
android:id="#+id/tracks_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false" />
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
when I run the program, it collapses just fine, expected behaviour.
but there seems to be another layout added between the collapsed toolbar and my Swiperefresh layout, it's as tall as the toolbar, but empty and unreactive
Somehow the toolbar is related to this issue as the hight of this phantom layout changes when I change the height of the toolbar
the space im refering to is the one on top of the recyclerView on the bottom.
Amazingly, this was fixed by moving the toolbar below the FrameLayout, when I moved it back up to reproduce the bug, it didn't do it. So I guess the lesson is "Sometimes you just have to move your code around" I guess maybe restarting the computer or shutting down Android Studio could have done the trick as well.

MvxListViews with checkboxes inside the ItemsSource are not selectable

I have an MvxListView that I'm showing some recipe cards in. When the user clicks a card they should be taken to a detail screen. The problem I'm running into is that when there is a CheckBox (bound or unbound) in the cell, the entire cell ignores the click event.
My MvxListView is created with:
<MvxListView
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource Recipes; ItemClick ShowRecipeDetailCommand"
local:MvxItemTemplate="#layout/use_recipe_list_item"
android:divider="#android:color/transparent"
android:dividerHeight="10dp" />
The List item is created with:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/use_detail_recipe_background"
android:padding="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Title"
android:id="#+id/tvTitle"
android:textSize="24sp"
local:MvxBind="Text Title"
android:layout_weight="1"
android:layout_toLeftOf="#+id/cbFavorite"
android:textColor="#color/use_detail_recipe_title_text" />
<!-- <CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cbFavorite"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:checked="false"
android:layout_weight="0" />-->
<View
android:id="#+id/vDivider1"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000"
android:layout_below="#+id/tvTitle" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Content"
android:id="#+id/tvContent"
android:singleLine="false"
android:layout_below="#+id/vDivider1"
local:MvxBind="Text Content"
android:textColor="#color/use_detail_recipe_content_text"
android:maxLines="4"/>
</RelativeLayout>
If the checkbox isn't commented out, this works. How can I work around this? Would it be possible to add a command to the click on my base RelativeLayout in the item?
Thanks for the tip Stuart. This is indeed not a MvvmCross issue but rather a general Android issue.
The solution was to add the following to each clickable item:
android:focusable="false"
android:focusableInTouchMode="false"
This comment got me on the right track https://stackoverflow.com/a/15859831/83301.