我一直在玩设计支持库,并遇到了一个小问题,我希望有人可以帮助我.
我正在使用一个包含ImageView的CollapsingToolbar,它在parralax中折叠.在CollapsingToolbar中,我还有一个TabLayout,它应该滚动我的ViewPager.我的问题是ViewPager没有出现.只有当我将ViewPager layout_height设置为match_parent或wrap_content时,才会出现此问题.如果我将它设置为600dp,那么问题就消失了,但随后视图最终变成了固定长度,这不是很好.
任何帮助都会受到赞赏!
这是我的XML
<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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
>
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
android:src="@drawable/stock_image"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_gravity="top"
/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
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.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-fragments android-viewpager androiddesignsupport android-collapsingtoolbarlayout
我最近将listview迁移到了recyclerview,这样我就可以在工具栏上消失,只显示tabs/RecyclerView.
现在,当我尝试将元素对齐到底部时,该元素从底部离开屏幕.
我必须添加60dp的保证金底部来修复它.但在我的FloatingActionButton中,那些60dp会影响动画,所以我不太喜欢它......
有谁知道这个伎俩???
这是我的代码:
第一个标签
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:background="#CCC">
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lista_tiendas"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:divider="@android:color/transparent"
android:dividerHeight="1.0sp" />
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="76dp"
android:src="@drawable/ic_add_white_24dp"
app:fab_type="normal"
app:fab_shadow="true"
app:fab_colorNormal="@color/spg_rosa"
app:fab_colorPressed="@color/spg_rosa_dark"
/>
<!--<android.support.design.widget.FloatingActionButton-->
<!--android:id="@+id/fab"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="right|bottom"-->
<!--android:src="@drawable/ic_add_white_48dp"-->
<!--app:backgroundTint="@color/spg_rosa"-->
<!--android:transitionName="@string/transition_add_pdv"-->
<!--app:borderWidth="0dp"-->
<!--app:elevation="8dp"-->
<!--app:fabSize="normal" />-->
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
第二个标签
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50">
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/maps_unavailable"
style="@style/placeholder_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/maps_unavailable"
android:visibility="gone" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="@dimen/map_pager_height"
android:layout_gravity="bottom"
android:layout_marginBottom="55dp"/> …Run Code Online (Sandbox Code Playgroud) 我有使用Toolbar的NavigationDrawer和AppBarLayout的活动.不幸的是,当我在子片段中使用TabLayout时,我看到工具栏和TabLayout之间的阴影.是否可以在TabLayout下方显示阴影?我不想将TabLayout移动到我的活动中,因为我只在一个片段中使用它.
我可以看到这个问题的解决方案:
您有什么想法如何在我的场景中正确使用它?
android android-fragments android-design-library androiddesignsupport
是否可以自定义android设计支持库中菜单项之间的间距NavigationView?
我的要求是创建一个子菜单,NavigationView其中菜单项之间的间距较小,然后是父菜单.
android navigation-drawer androiddesignsupport android-navigationview
如何使用书法将自定义字体应用于设计支持库中的TabLayout?
我已经得到它在Java工作,大多数答案似乎参考.(例如,在Android设计支持TabLayout中更改选项卡文本的字体)
我不想做自定义课程,我只想使用书法.(https://github.com/chrisjenx/Calligraphy)
谢谢
我需要为我正在开发的应用程序选项卡.所以我最终得到了tablayout,它包含很少的标签.代码如下:
private void setupNavTab() {
int[][] states = new int[][]{
new int[]{android.R.attr.state_selected},
new int[]{-android.R.attr.state_selected},
new int[]{-android.R.attr.state_enabled}
};
int[] colors = new int[]{
ContextCompat.getColor(getActivity(), R.color.cricut_selected_green),
ContextCompat.getColor(getActivity(), R.color.nav_bar_unselected_content),
ContextCompat.getColor(getActivity(), R.color.edit_button_text_color_inactive)
};
ColorStateList cslist = new ColorStateList(states, colors);
if (tabs != null) {
tabs.removeAllTabs();
tabs.setTabTextColors(cslist);
firstTab = tabs.newTab().setTag(TAB_FIRST);
View customFirstTabView = LayoutInflater.from(getActivity()).inflate(R.layout.tab_item_layout, null, false);
firstTabView = (TextView) customFirstTabView.findViewById(R.id.textContainer);
firstTabView.setText(R.string.first);
firstTabView.setTextColor(cslist);
firstTab.setCustomView(customFirstTabView);
secondTab = tabs.newTab().setTag(TAB_SECOND);
View customSecondView = LayoutInflater.from(getActivity()).inflate(R.layout.tab_item_layout, null, false);
secondTabView = (TextView) customSecondView.findViewById(R.id.textContainer);
secondTabView.setText(R.string.second);
secondTabView.setTextColor(cslist);
secondTab.setCustomView(customSecondView);
thirdTab = tabs.newTab().setTag(TAB_THIRD);
View customThirdTabView
= …Run Code Online (Sandbox Code Playgroud) I am using floating action button of Android Design Library in my app which is working fine on lollipop and above versions but getting crashed on pre-lollipop version (4.0-4.2.2) . I am really stuck and unable to figure out the issue .
Error:
FATAL EXCEPTION: main android.view.InflateException: Binary XML file line #396: Error inflating class android.support.design.widget.FloatingActionButton at android.view.LayoutInflater.createView(LayoutInflater.java:619) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693) at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) at android.view.LayoutInflater.inflate(LayoutInflater.java:495) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at com.example.sony.bluedolphintrialapp.DhampureFragment.onCreateView(DhampureFragment.java:18) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955) android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138 android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) …
android floating-action-button android-design-library androiddesignsupport
在我的应用程序中,我有一个活动.此活动的主题是正常的pre-L,但是对于L及以上,它被覆盖,具有:
...
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/statusTrans</item>
...
Run Code Online (Sandbox Code Playgroud)
此活动具有这样的布局(fsw表示该节点适合SystemWindows)以提供Material效果.
CoordinatorLayout (fsw)
L AppBarLayout (fsw)
L CollapsingToolbarLayout (fsw)
L ImageView (fsw)
L Toolbar
L TabLayout
L ViewPager
L FAB
Run Code Online (Sandbox Code Playgroud)
事情是,我DialogFragment通过事务向这个活动添加一个全屏,通过添加到具有这种布局的android.R.id.content
CoordinatorLayout (fsw)
L AppBarLayout (fsw)
L CollapsingToolbarLayout (fsw)
L FrameLayout
L Toolbar
L TabLayout
L NestedScrollView
Run Code Online (Sandbox Code Playgroud)
初始布局绘制statusBar,然后Toolbar按预期绘制它(即插入内插),但添加的片段布局Toolbar直接在statusBar下绘制,我似乎无法将其绘制正确.
我不知道我做错了什么.下面有两个屏幕截图显示问题.
.
还有(奖金问题!)
在同一个Activity中,我设置了Viewpager一个ScrollingViewBehavior.填充的片段Viewpager有一个ViewFlipper切换其中一个:loadingView(ProgressBar),contentView(RecyclerView)和emptyView(LinearLayout).这确保了如果theres内容,则活动具有所需的滚动效果.
emptyView出现问题,因为它没有正确居中.我附上了一张图片.
我该如何纠正(或破解)这种行为?
我正在努力实现这样的目标https://material.google.com/components/bottom-navigation.html#bottom-navigation-behavior
但是回收器视图隐藏在工具栏下方,并且对BottomNavigationView没有任何影响
以下是我的代码
activity_main.xml中
<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.BottomNavigationView
android:id="@+id/nm_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimaryDark"
android:foregroundTint="@color/colorAccent"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:menu="@menu/nav_menu" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/nm_bottom"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
item.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="4dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="2dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="4dp">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription="TODO"
android:src="@drawable/ic_storage" />
<TextView …Run Code Online (Sandbox Code Playgroud)