ConstraintLayout takes extra space around it when it is included inside Toolbar (android.support.v7.widget.Toolbar) widget - toolbar

Today I'm facing an unexpected problem. When trying to use ConstraintLayout inside a Toolbar(android.support.v7.widget.Toolbar) widget , it's takeing extra space around it for nothing.And when I use it (ConstraintLayout with same xml code) inside anther layout like LeanearLayout it works fine (It does not take any space unexpectedly around it).
my_inside_toolbar.xml
<?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:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f90511"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">
<Button
android:id="#+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="#000"
android:text="Button"
android:textColor="#fff"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/button5"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="#0b8653"
android:text="Button"
android:textColor="#fff"
app:layout_constraintLeft_toRightOf="#+id/button4"
app:layout_constraintRight_toLeftOf="#+id/button6"
app:layout_constraintTop_toTopOf="#+id/button4" />
<Button
android:id="#+id/button6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="#000"
android:text="Button"
android:textColor="#fff"
app:layout_constraintLeft_toRightOf="#+id/button5"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/button5" />
</android.support.constraint.ConstraintLayout>
design view for the above xml below:
When I include this xml inside my_toolbar.xml problems arises.
Here is
my_toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<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="#f5e903">
<include
android:id="#+id/la"
layout="#layout/my_inside_toolbar.xml" />
</android.support.v7.widget.Toolbar>
Design view for the above xml below:
Note: Here Yellow color is the background for toolbar widget. And the extra yellow background shows the unexpected space.
Now my questions:
Is it possible to use ConstraintLayout inside a Toolbar so that it can cover the full body of its parent (toolbar)?
If possible then how to solve the problems which I am facing now?
Any answer and suggestion will be praised.

This is the part of new Material Design Specification introduced in version 24.0.0 of Design Support library.
It is possible to remove the extra space by adding the following property to Toolbar widget.
app:contentInsetStartWithNavigation="0dp"
As mention by #kocus in comments adding app:contentInsetStart="0dp" solved his problems, I originally misinterpreted the problem.

Related

Focusing button by default in android tv

I have an Android tv Layout with two buttons:
Buttons are not focused
I want one button to be focused by default:
Focusing choose a TV button by default.
I have tried a few methods.
In java file
final Buttonspinner spinner = findViewById(R.id.choose_folder);
spinner.requestFocus();
spinner.setFocusable(true);
In xml
android:state_focused="true"
Still, it's not getting focused by default.
How can I achieve this?
In code:
spinner.setFocusableInTouchMode(true);
spinner.setFocusable(true);
spinner.setFocusedByDefault(true);
spinner.requestFocus();
Alternatively in XML:
<Button
android:id="#+id/choose_folder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/choose"
android:focusableInTouchMode="true"
android:focusable="true"
android:focusedByDefault="true">
<requestFocus/>
</Button>
Maybe a bit overkill, but either one of these should cover all bases.

Android Buttons are overlapping while run

I'm trying to create an Android App to control an RC-Car.
I'm just at the beginning and my App has only two Buttons. I'm using Android Studio and in my layout the two Buttons are among each other. But when I run the App only the top Button is shown. I tried many different things and I couldn't find a solution or why it is like that.
Here's my Layout:
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="e.monaw.rc_car_v1.MainActivity">
<Button
android:id="#+id/btnOnOff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btSpeed"
android:layout_alignTop="#+id/btSpeed"
android:text="On/Off"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="97dp" />
<Button
android:id="#+id/btSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Speed"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="16dp" />
</android.support.constraint.ConstraintLayout>
I hope you can help me fix this problem! As how it is now I can't test it and I can't go on working on my App.

Add button to BrowseFragment

I am developing an Android TV app using Leanback support library. I need to display a button in the top right corner (below the badge) of BrowseFragment. (as on below image)
Here is the layout code
<?xml version="1.0" encoding="utf-8"?>
<fragment 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/main_browse_fragment"
android:name="tv.bishan.com.videoapp.ui.ItemFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:deviceIds="tv"
tools:ignore="MergeRootFrame"/>
How can I achieve this? Unable to find any solution from Google.
You can create custom TitleView and set it to the activity theme using the browseTitleViewLayout attribute.

CollapsingToolbarLayout Scrolling issues

I have a problem with the CollapsingToolbarLayout from the already in Android Studio given ScrollingActivity.
The scrolling down motion works perfectly, but when I want to scroll up, it always shows me that the end of the screen is reached without expanding the Toolbar again. To expand the Toolbar, I have to scroll up again, when the end of the screen is reached.
As I'm not really good in explaining the problem I uploaded a Video on YouTube so you can see it by yourself.
VIDEO: https://youtu.be/WrzsY2ooj9o
Also you can see a little bug in there too. The Toolbar collapses by itself sometimes just by making a "bad motion" with the finger, I think you can see it at 0:11.
Thankful for any Help!
<?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:fitsSystemWindows="true"
tools:context="com.appmac.ron.myapplication.ScrollingActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_scrolling" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_email"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
update to 26.0.0-beta2. AppbarLayout should be work as expect. Details:Carry on Scrolling
Ok, I think a third party library can make it work. In fact, I decompiled others app and find this:)
All above was deperated, I find this. There is a easy way to solve this problem. Just set a OnScrollChangeListener listener to your nestedsrollview. The key code is below:
nestScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
#Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX,
int oldScrollY) {
if(scrollY == 0) appBarLayout.setExpanded(true);
}
});
The animation will do by method appBarLayout itself.
With reference to Google issue tracker,
Issue is resolved on latest library version 26.1.0.
If any issue persists, please report at Google issue tracker they will re-open to examine.

Transparent button on Google Maps Android API v2

I've been wrestling with this for a while and I can't seem to figure it out. Maybe someone here has dealt with something similar.
I'm trying to place a button on top of my Google map and have the button be transparent.
Here's what I've written, but no luck:
<FrameLayout 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=".MainActivity"
android:keepScreenOn="true" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
<LinearLayout
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:alpha=".30"
android:text="#string/button1_label"
android:background="#android:drawable/btn_default" />
</LinearLayout>
Also, if you see anything wrong with my code, feel free to point it out.
android:alpha was added in API 11. Use your own transparent background image (or a set of images in statelist).
If this doesn't help, post the screenshot. This can make answering easier.

Resources