i want to make a view that will be below another view and overlays it too
i made the following
<RelativeLayout android:layout_height="wrap_content" android:layout_width="wrap_content">
<include layout="#layout/toolbar" android:id="#+id/tool"
/>
<include layout="#layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/tool"
android:layout_marginBottom="30dp"
/>
</RelativeLayout>
but it didn't work, any solutions?
First, you'll need to reverse the order of the views, toolbar should hide content_main so it should be added after it.
Second, you can use negative margins for this, you tell content_main to be below toolbar, and then put a negative top margin on it, so it moves a bit higher, and beneath toolbar.
Example:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000" >
<TextView
android:text="first line, will be partially covered. fdjkfsjdf kldsjfkdsljfklds "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolbar"
android:layout_marginTop="-20dp"
android:textSize="36sp"
android:fontFamily="sans-serif-light"
android:background="#00ff00"/>
<TextView
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#0000ff"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textSize="36sp"
android:text="TOOLBAR" />
</RelativeLayout>
And result:
Try to use a FrameLayout, instead of RelativeLayout.
Related
I'm stuck with an issue and I have browsed the entire internet for a solution but nothing is working for me.
I have added an imageview inside my toolbar but it's slightly towards the right. It doesn't align centrally, it's shifted a bit towards the right. When i align the imageview to the left, there's an unknown padding/gap between the imageview and the left side of the toolbar. Following is my XML code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<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:fitsSystemWindows="true"
tools:context=".NavigationDrawerHomeScreen.BaseActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_home_activity"
android:layout_width="match_parent"
android:layout_height="45dp"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
android:contentInsetStartWithNavigation="0dp"
android:minHeight="?attr/actionBarSize"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/logo_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/fixer_title_thick" />
</RelativeLayout>
<android.support.v7.widget.SearchView
android:id="#+id/search_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:showAsAction="ifRoom"
android:visibility="gone">
</android.support.v7.widget.SearchView>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/container_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/home_bg" />
</FrameLayout>
<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_centerInParent="true"-->
<!--android:text="this is base" />-->
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
<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:background="#2A2929"
android:backgroundTint="#2A2929"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_home_customer"
app:itemTextAppearance="#style/NavDrawerTextStyle"
app:itemTextColor="#fff"
app:menu="#menu/activity_home_customer_drawer">
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:clickable="true"
android:orientation="vertical">
<!-- any addition stuff you want in yoour footer layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="50dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Search Radius"
android:textColor="#color/white" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:clipChildren="false">
<com.crystal.crystalrangeseekbar.widgets.CrystalSeekbar
android:id="#+id/rangeSeekbar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bar_color="#color/blue"
app:left_thumb_color="#color/blue_dark" />
<TextView
android:id="#+id/textMin1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rangeSeekbar1"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:text="0"
android:textColor="#color/white"
android:textSize="16dp" />
<TextView
android:id="#+id/textMax1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/rangeSeekbar1"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:text="100"
android:textColor="#color/white"
android:textSize="16dp" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#1E88E5">
<TextView
android:id="#+id/logout_footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="20dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:drawableLeft="#drawable/ic_logout_white_24dp"
android:drawablePadding="32dp"
android:text="Logout"
android:textColor="#fff"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
</android.support.design.widget.NavigationView>
The app:contentinset/android:contentinset solution works for some people but it doesnt work for me.
here's the image http://imgur.com/a/Vp2g6.
I had this same problem, and I tried a lot of things like setting
app:contentInsetStart ="0dp" ;
app:contentInsetStartWithNavigation = "0dp" ;
It didn't work. I even set them to a negative value, but it didn't work. I tried adding a right margin to my child view but it reduced the visible size of child view instead of occupying that left space. So probably child views are not allowed in this space.
So after spending some time I figured there are 2 ways to workaround this problem, one is preferred other I'd not prefer. First let me tell you the one I do not prefer:
Custom Implementation of the Up button: This problem only arises when in your Java Class for this layout you set this toolbar as your ActionBar and you
setDisplayHomeAsUpEnabled(true);
Without this command this problem doesn't exist. So if you don't use the default back button and implement one your own by putting an imageView and providing onClick implementation, this should work fine.
Make ChildViews as rather Siblings: The other method is using the property of toolbar of it being just another view.
I prefer this method because by using this method you can use the android's default up button. The only thing you need to do is - instead of defining child views inside the toolbar, make the child view and toolbar as siblings in a Linear or Relative Layout. This way you can reduce the left space only to "wrap_content" of the toolbar and utilise the left space in other child views. In my app, I even had an onClick functionality on the toolbar which can now be done by giving that functionality on the parent of both the layouts i.e. set the onClick on the LinearLayout.
Though I still don't know the exact reason why the left space exists or is there a way to disable it, but this is a pretty clean method to work around this.
I want is the following sort of layout:
<CoordinatorLayout>
<ToolBar></ToolBar>
<RelativeLayout></RelativeLayout>
<RecyclerView></RecyclerView>
<LinearLayout>
<EditText></EditText>
</LinearLayout>
<CoordinatorLayout>
However, my issue is when I click on my EditText, the keyboard pops up and shows the RecyclerView perfectly, but when I try to scroll further up, I can't seem to see my RelativeLayout, nor can I see my ToolBar. However, when I don't have the keyboard up, I can see everything fine. Here are some images showing what's happening:
I understand it is most likely because I don't have a parent ScrollView that nests the entire layout, but I can't seem to have that because of my RecyclerView. Is there either a. a way to implement a sort of custom RecyclerView so I can have a ScrollView parent layout or b. find some way for me to be able to scroll and see my ToolBar and RelativeLayout in addition to my RecyclerView? I've included my attempt with a ScrollView but I still can only see the RecyclerView when I click on the EditText. Any help is appreciated. Thanks!
Code:
AndroidManifest.xml:
<activity android:name=".com.tabs.activity.Comments"
android:label="View Post"
android:theme="#style/AppTheme.NoActionBar"
android:configChanges="keyboardHidden"
android:windowSoftInputMode="adjustPan|stateVisible|stateAlwaysHidden">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".com.tabs.activity.news_feed"/>
</activity>
comments.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:flatui="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fresco="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/comments_coordinator_layout">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/comments_appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/layout_comments">
<RelativeLayout
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/view_post"
android:layout_width="match_parent"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:layout_height="175dp"
android:background="#e6e6e6">
<com.facebook.drawee.view.SimpleDraweeView
android:layout_marginTop="15dp"
android:id="#+id/poster_picture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginLeft="10dp"
fresco:placeholderImage="#mipmap/blank_prof_pic"
fresco:roundedCornerRadius="5dp"
fresco:roundAsCircle="true"
/>
<TextView
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="#id/poster_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:id="#+id/poster_name"/>
<TextView
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:layout_toRightOf="#id/poster_name"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:id="#+id/post_date"/>
<TextView
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/poster_picture"
android:layout_below="#id/poster_name"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/view_status" />
</RelativeLayout>
<LinearLayout
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<com.cengalabs.flatui.views.FlatEditText
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:paddingLeft="10dp"
android:gravity="bottom|left"
android:cursorVisible="false"
android:hint="Comment back!"
android:inputType="textMultiLine"
flatui:fl_fieldStyle="fl_box"
android:scrollHorizontally="false" />
<com.cengalabs.flatui.views.FlatButton
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
flatui:theme="#array/sea"
flatui:fl_textAppearance="fl_light"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/view_post"
android:layout_above="#id/send_message"
android:id="#+id/view_comments">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
According to:
I understand it is most likely because I don't have a parent
ScrollView that nests the entire layout, but I can't seem to have
that because of my RecyclerView. Is there either a. a way to
implement a sort of custom RecyclerView so I can have a ScrollView
parent layout or b. find some way for me to be able to scroll and see
my ToolBar and RelativeLayout in addition to my RecyclerView?
I've included my attempt with a ScrollView but I still can only see
the RecyclerView when I click on the EditText. Any help is
appreciated. Thanks!
So you need to extend range of existing ScrollView view. Just put AppBarLayout and RelativeLayout view into new vertical oriented 'LinearLayout', as ScrollView takes only one view. This new created ViewGroup would be an only child of 'CoordinatorLayout'.
Once you wrap AppBarLayout and RelativeLayout' into new madeLinearLayout, put it into existingScrollView`.
Hope you now understand how to do it. If not, tell me and I would tomorrow in the early morning edit my post and change your actual code with desired one.
put your <RecyclerView> in the one <LinearLayout>
and set your linearlayout as match_parent but in your RecyclerView set height="0dp" and use weight="1" like this :
<CoordinatorLayout>
<ToolBar></ToolBar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></RecyclerView>
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_anchorGravity="bottom"></EditText>
<CoordinatorLayout>
and then, when your keyboard opens your recyclerview will not be under keyboard and your can scroll to see items under keybard
good lock
I can't scroll my RecyclerView to the end. It cut off my last element and I completly don't know why. I have another RecyclerView in my project, which also seems to be broken.
Here is my layout code:
<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"
android:id="#+id/container"
android:padding="10dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cv"
app:cardCornerRadius="2dp"
app:cardUseCompatPadding="true">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="220dp"
android:orientation="horizontal">
(...)
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView17"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="HISTORIA"
android:id="#+id/textView17"
android:layout_below="#+id/cv"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Another broken RecyclerView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.praca_inz.Fragments.PetrolFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:scaleType="center"
android:src="#drawable/ic_editor_mode_edit"
android:layout_marginBottom="70dp"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Any ideas, because I don't have any.
You've got an issue in your first layout. In a RelativeLayout, a match_parent sized element will have exactly the same size as the layout itself. That's the case of your RecyclerView. However, it's not at the top of the layout, as it's below the #+id/textView17 TextView. So you're missing roughly 250~300dp of your RecyclerView (card's + text's height). You should probably use a vertical LinearLayout in this case, that's exactly what they're made for. Just set the RecyclerView's height to 0 and weight to 1.
You should set padding bottom in your RecyclerView. Like this:
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView17"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:paddingBottom="20dp" />
I hope help you, and sorry for my bad english.
There was a problem with ViewPager in MainActivity layout. The solution was to set a paddingTop parameter, to 105dp (to cover Toolbar and TabLayout) and delete app:layout_behavior="#string/appbar_scrolling_view_behavior" parameter.
Before:
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
After:
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="105dp"/>
Thank you #oguzhand, for directing me to solution!
Add alignParentBottom="true" to the recyclerView. That should pin it to the bottom edge and the top will be pinned to the textview via the layoutBelow tag you already have in place
I am trying to make a bottom bar using the toolbar and aligning it to the parent bottom. This is how it looks:
But somehow as mentioned in the image, their is a lot of empty space due to which the layout is not exactly centered. Why is that happening?
bottom_tool_bar.xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/ColorPrimaryLight"
android:elevation="4dp"
android:layout_alignParentBottom="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/origin_select"
android:src="#mipmap/ic_action_play"
android:background="#drawable/feedback_background"
android:onClick="choose_origin_button"
/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/destination_select_select"
android:src="#mipmap/ic_action_stop"
android:background="#drawable/feedback_background"
android:onClick="choose_destination_button"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/poi_select"
android:src="#mipmap/ic_action_pause"
android:background="#drawable/feedback_background"
android:onClick="choose_interest_button"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
The layout file for the concerned activity:
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
>
</include>
<include
android:id="#+id/bottom_tool_bar"
layout="#layout/bottom_tool_bar">
</include>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/plot_path_map"
android:layout_below="#+id/tool_bar"
android:layout_above="#+id/bottom_tool_bar"
android:name="com.google.android.gms.maps.MapFragment"
/>
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/submit_button"
android:text="Submit"
android:textColor="#FFFFFF"
android:layout_centerHorizontal="true"
android:background="#drawable/feedback_background"
android:layout_centerVertical="true"
android:textSize="20sp"
android:layout_alignParentBottom="true"
android:visibility="invisible"
android:onClick="submit_button_click"
/>
</RelativeLayout>
If you want to place the toolbar at the bottom, this is what you should be doing.
Use a LinearLayout with alignParentBottom="true"
<RelativeLayout
android:id="#+id/mainLyt"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Some layout things -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/bottomBar">
<!-- some scrolling content -->
</ScrollView>
<LinearLayout
android:id="#+id/bottomBar"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<!-- Some Buttons -->
</LinearLayout>
</RelativeLayout>
As you mentioned about spacing, which I believe is another question, you can modify it by using the following attributes inside your ToolBar.
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
Make a separate layout file and name it tool_bar.xml and make sure LinearLayout is your root layout.
Then in your activity type this:
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
></include>
Then give weight of 0.3 to all your ImageViews and layout:width and layout:height as wrap_content
Use below line to avoid left side gap in activity class.
mToolbar.setContentInsetsAbsolute(0, 0);
Look below code for avoid top and bottom space.
<ImageView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/origin_select"
android:src="#mipmap/ic_action_play"
android:background="#drawable/feedback_background"
android:onClick="choose_origin_button"
/>
In your image view width should be a wrap_content and height should be 0dp
For centering the Views you have many options two are the following (I believe the second is best):
First include weigthsum in your linearlayout, I like to use 100 since this helps me think in percentage, then include 2 stump framelayout in order to push your imageviews to the horizontal center and to let them keep responsive properties by using weight like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:orientation="horizontal"
>
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"/>
<ImageView
android:id="#+id/origin_select"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="13"
android:background="#drawable/feedback_background"
android:onClick="choose_origin_button"
android:src="#mipmap/ic_action_play"
/>
<ImageView
android:id="#+id/destination_select_select"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="13"
android:background="#drawable/feedback_background"
android:onClick="choose_destination_button"
android:src="#mipmap/ic_action_stop"/>
<ImageView
android:id="#+id/poi_select"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="13"
android:background="#drawable/feedback_background"
android:onClick="choose_interest_button"
android:src="#mipmap/ic_action_pause"/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"/>
</LinearLayout>
As you can see both framelayout have nothing inside but they help you push your other ImageViews to the center they both give you 60% of space used and leave you just another 40% for your ImageViews thus they have each 13%.
On the other hand you can use a RelativeLayout as your parent element instead of LinearLayout and position Imageview with id: destination_select_select align center to parent both horizontal and vertical and then position the other two imageviews at the side of the one centered in the middle. This option might be the best:
Like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="#+id/origin_select"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/feedback_background"
android:onClick="choose_origin_button"
android:src="#mipmap/ic_action_play"
android:layout_alignLeft="#+id/destination_select_select"
/>
<ImageView
android:id="#+id/destination_select_select"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="match_parent"
android:background="#drawable/feedback_background"
android:onClick="choose_destination_button"
android:src="#mipmap/ic_action_stop"/>
<ImageView
android:id="#+id/poi_select"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignRight="#+id/destination_select_select"
android:background="#drawable/feedback_background"
android:onClick="choose_interest_button"
android:src="#mipmap/ic_action_pause"/>
</RelativeLayout>
To avoid top and bottom spaces,
Add this line
android:minHeight="0dp"
to the <android.support.v7.widget.Toolbar> properties.
I'm trying to use a couple views within a support.v7.widget.Toolbar, but it looks like they're all placed as if in a horizontal LinearLayout. I'm looking to create something more like this where the EditText ends past the overflow menu, rather than where the overflow menu begins. Here's my currently layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="250sp"
android:background="#color/primary"
android:gravity="bottom"
android:minHeight="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button_id"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/url"
android:textColor="#color/accent"
android:textSize="16sp" />
<EditText
android:id="#+id/url_text_field_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:maxLines="1" />
<TextView
android:id="#+id/output_text_view_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/initial_output_text_id"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Here's a screenshot. You can see the views are in line with the share button and overflow menu. The title is also hidden on the left hand side by the views. How would I have a second row for my views in the Toolbar so they span the width of the page? Hopefully, I'm just missing something small, as I'm new to Android. Thanks in advance for the help.
You could, probably, put a vertical LinearLayout into your Toolbar