I'm using this library https://github.com/astuetz/PagerSlidingTabStrip to create a PagerTabStrip.
My output
You can see that after my tabs I have some empty space.
I want to make the tabs fit all the screen, or at least center the tabs.
Is that possible?
<com.astuetz.PagerSlidingTabStrip
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:background="#color/facebook_theme_light"
android:id="#+id/activity_posts_tabs"
android:layout_width="match_parent"
android:layout_height="48dip" />
<android.support.v4.view.ViewPager
android:background="#color/facebook_theme_dark"
android:id="#+id/activity_posts_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/activity_posts_tabs"
tools:context=".MainActivity" />
Went looking for a solution for this, and there is one already built into the library, just use:
psts:pstsShouldExpand="true"
and the tabs will expand and center in the layout.
This should be a comment, but it looked crazy when I tried to put it in comment form so here you go:
If you go to the sample xml for the library you provided
you will find that the xml has the view -
<com.astuetz.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="62dip"
android:layout_below="#+id/image"
android:background="#drawable/background_tabs_diagonal"
app:pstsDividerColor="#00000000"
app:pstsIndicatorColor="#FF33B5E6"
app:pstsTabPaddingLeftRight="14dip"
app:pstsUnderlineColor="#FF33B5E6" />
This has a width of "match_parent". What you need to do in your app is change your equivalent of this to "wrap_content" and add android:layout_gravity="center_horizontal".... or something along those lines since I haven't tested it.
EDIT
You could also try wrapping it in a container
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.astuetz.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="wrap_content"
android:layout_height="62dip"
android:layout_below="#+id/image"
android:layout_centerInParent="true"
android:background="#drawable/background_tabs_diagonal"
app:pstsDividerColor="#00000000"
app:pstsIndicatorColor="#FF33B5E6"
app:pstsTabPaddingLeftRight="14dip"
app:pstsUnderlineColor="#FF33B5E6" />
</RelativeLayout>
Related
I've using the Fragment inside the Navigation Drawer.
In Drawer there are 7 more option menus are presents and all other working fine.
Only this fragment tasking 3sec time to show the views.
I've find using debug mode, below this only line taking that much time to execute.
final View view=inflater.inflate(R.layout.fragment_vehicle_inspection,container,false);
Moreover I've using 4 include layout in XML part.
<?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="match_parent">
<LinearLayout
android:id="#+id/lat_inspection_vendor_name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_05dp"
android:orientation="horizontal">
<TextView
android:id="#+id/txt_inspection_vendor_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableEnd="#drawable/ic_action_edit"
android:gravity="center"
android:maxLines="1"
android:textColor="#color/colorAccent"
android:textSize="#dimen/margin_15sp"
android:textStyle="bold" />
</LinearLayout>
<include
android:id="#+id/include_inspection_function_layout"
layout="#layout/fragment_inspection_function_layout_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lat_inspection_vendor_name_layout"
android:layout_marginTop="#dimen/margin_05dp"
android:visibility="gone" />
<ScrollView
android:id="#+id/scroll_inspection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/include_inspection_function_layout"
android:layout_marginTop="#dimen/margin_10dp"
android:focusableInTouchMode="true"
android:focusable="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/fragment_inspection_vendor_details_card" />
<LinearLayout
android:id="#+id/lat_inspection_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<include layout="#layout/fragment_inspection_vehicle_form_row_card" />
<include layout="#layout/fragment_inspection_vehicle_features_row_card" />
<include layout="#layout/fragment_inspection_vehicle_form_penalty_row_card" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I hope include part is not affect inflate view.
I've using 26- EditText, 26-checkbox and 30-TextViews inside the include layout.
My concern is Inflating too much number of views only taking time.
Please assist me to encounter this problem.
Thanks in advance.
It's because too much view's in your layout file and yes include part affect your inflation process. Try to reduce number of view.
Share you layout design image so i can give you a suggestion.
It's because you are showing some high resolution image or any other background resource so it may happen to take some time to draw view in your fragment
Some of my floating action buttons don't remain where I want, and I cannot understand why.
The first is how they should be (and actually sometimes it works), the other two images show how they behave sometimes... and I cannot find a "pattern" in this behavior.
This is the layout (only one half):
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/lay_attivita_edit_ubicazioni"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="#dimen/list_padding_lateral"
android:paddingRight="#dimen/list_padding_lateral">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:id="#+id/container_attivita_edit_origini">
<TextView
style="#style/FieldLabel"
android:layout_marginTop="20dp"
android:text="#string/attivita_edit_origini" />
<ListView
style="#style/ListView"
android:id="#+id/list_attivita_edit_origini"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:background="#drawable/border_rectangle" />
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
style="#style/FloatingActionButton.Small"
android:id="#+id/fab_attivita_edit_ubicazioni_edit_origini"
app:layout_anchor="#id/list_attivita_edit_origini"
app:layout_anchorGravity="top|right|end" />
</android.support.design.widget.CoordinatorLayout>
I tried also to se anchor and anchorGravity programmatically but the result is the same. It could happen because depending on some logic one of the two sections could not be visible, in case I make them invisible at the end of OnCreateView.
It doesn't depend on the visibility of the "anchor list" because the fab move even if I always leave both the lists visible.
I tried also to change programmatically anchor and anchorId of the fab at every change of visibility of them or of their lists, nothing.
CoordinatorLayout.LayoutParams editOrigineFabParams = (CoordinatorLayout.LayoutParams)editOrigineFab.LayoutParameters;
editOrigineFabParams.AnchorId = Resource.Id.list_attivita_edit_origini;
editOrigineFabParams.AnchorGravity = (int)(GravityFlags.Top | GravityFlags.Right | GravityFlags.End);
editOrigineFab.LayoutParameters = editOrigineFabParams;
With the same conditions/code sometimes they work and sometimes they don't. It looks like a bug in Android. I tried with Android 7.0 and 7.1, Xamarin.Android.Support.Compat.25.3.1.
Anyone who had a similar problem or who has an idea of what could be the reason?
Use FAB by james montemagno.
Add FAB by james montemagno from nuget to your project.
https://www.nuget.org/packages/Refractored.FloatingActionButton/
<Refractored.Fab.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="#drawable/ic_action_content_new"
app:app_colorNormal="#color/primary"
app:app_colorPressed="#color/primary_pressed"
app:app_colorRipple="#color/ripple" />
use layout_gravity for positioning .
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:src="#drawable/ic_edit"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp" / >
I need to make FloatingActionButton always stick to the bottom of my fragment where I display WebView. The problem is that the button in my current XML is cut in half and I can't manage to fix it. Here is my layout.
<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"
android:background="#color/colorBackgroundWhite"
tools:context=".fragments.CpuComparisionFragment">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/button_compare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="#dimen/fb_margin_16dp"
android:layout_marginEnd="#dimen/fb_margin_16dp"
android:alpha="0.7"
android:src="#drawable/ic_compare" />
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
What am i doing wrong? Any ideas how to fix this? Here is screenshot how my app looks now.
It seems the android version installed on the device you're testing your app on doesn't support some of your xml attributes. Anyways, replace the FAB code with the below snippet. I hope it work for you.
<android.support.design.widget.FloatingActionButton
android:id="#+id/button_compare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="#dimen/fb_margin_16dp"
android:layout_marginEnd="#dimen/fb_margin_16dp"
android:alpha="0.7"
app:layout_anchorGravity="bottom|right|end"
android:src="#drawable/ic_compare" />
Try to add android:fitsSystemWindows="true" to your FrameLayout .
I am learning Android these days, and I am having some trouble implementing something. When I click on the image icon, I want a menu to appear from below. The screenshot is as below. (Sorry it's in chinese....)
There's awesome library on github to get your task done.
All you need to do is setup your layout in two part as describe in below code
part 1: Your main activity(main frame)
part 2: bottom Panel which will be shown when user swipe/click on button.
You must check how to set "anchor point true" in library document.
<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottom_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoDragView="#+id/dragView"
sothree:umanoPanelHeight="68dp"
sothree:umanoParalaxOffset="10dp">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<RelativeLayout
android:id="#+id/panel"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--This is bottom layout.-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#0000FF"
android:text="Button 1" />
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#0000FF"
android:text="Button 1" />
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#0000FF"
android:text="Button 1" />
</LinearLayout>
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
I think what you are trying to do here is to replicate the action sheet of iOS in android. There is this library which does exactly what you are looking for, https://github.com/baoyongzhang/android-ActionSheet . You can either have it as it as it is provided by author or you can clone it and suit your need accordingly. I would prefer if you could clone it as a module in your app that way you have limitless way to re-design it. If you need help on that let us know
You can simply follow the below link , it will implement what u need :
http://trickyandroid.com/fragments-translate-animation/
This will be done through Transition Fragment Animation .
I have a view with articles. It uses "include", and I'm trying to make a little margin between them. However, "android:layout_marginTop" does not seem to have any impact on the layout.
What am I doing wrong?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include android:id="#+id/article1" layout="#layout/mainarticle" />
<include android:id="#+id/article2" android:layout_marginTop="10dip" layout="#layout/article" />
<include android:id="#+id/article3" android:layout_marginTop="10dip" layout="#layout/article" />
<include android:id="#+id/article4" android:layout_marginTop="10dip" layout="#layout/article" />
<include android:id="#+id/article5" android:layout_marginTop="10dip" layout="#layout/article" />
</LinearLayout>
You should add the android:layout_width and android:layout_height attributes in the include tag. Otherwise, the margins are not taken into consideration.
However, if you want to override layout attributes using the <include> tag, you must override both android:layout_height and android:layout_width in order for other layout attributes to take effect.
https://developer.android.com/training/improving-layouts/reusing-layouts.html#Include
I had the same problem and the answer from Kamen Goranchev doesn't work for me.
I have used ADT's feature "Extract include..." from the layout editor to extract some commonly used badges as a list of TextView-elements. So the Extract-include-tool wrapped my TextView-Elements in a merge-tag, which usually would be fine.
But, according to the very helpful sourcecode-link from boiledwater I see in line 888 https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/LayoutInflater.java#L888, the layout-attributes from the include-tag itself are only parsed if the include doesn't have the merge-tag as its root-element.
So I removed the merge-tag from the include and used another ViewGroup-tag like e.g. FrameLayout. Then the margins in the include-tag are working as expected.
include tag support below properties:
Any android:layout_* attributes which you can overwrite.
android:id attribute.
layout attribute.
android:visibility attribute.
Etc:
include android:id=”#+id/news_title”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
layout=”#layout/title”/>
Please read:
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/LayoutInflater.java#L777
http://developer.android.com/training/improving-layouts/reusing-layouts.html
Another solution would be to add Space before include:
<Space
android:layout_height="8dp"
android:layout_width="match_parent" />
must insert include into other layout.
e.g. Relativelayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp">
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/sub_edit_new_customer" />
</RelativeLayout>
In my case I solved the problem by adding some padding.
The layout you want to include:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"> <!-- add padding here -->
<!-- your custom layout -->
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>