我在这里引用一个关于材料设计的精彩演示.它有标签,但是当我添加太多标签项时会被压扁(见截图).如何让它水平滚动?

我相信下面是我应该做出改变的布局,但我梳理了文档并且似乎无法得到它,请帮忙!
<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.support.design.widget.AppBarLayout
android:id="@+id/appbar"
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:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<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" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_done" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android material-design android-design-library android-support-design
当在片段内滚动recyclerView时,我使用支持设计库来显示/隐藏工具栏,如https://github.com/codepath/android_guides/wiki/Handling-Scrolls-with-CoordinatorLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<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:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
<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:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
它工作,现在我想以编程方式启用/禁用工具栏滚动,因为我使用片段,我需要为某些片段停止此功能.
谷歌发布了支持库23.2的新更新,因为他们添加了底页功能.任何人都可以告诉如何使用该库实现该底部工作表.
更新到v23.2.0后,recyclerview项目有奇怪的行为:空间非常大.更新到设计库23.2.0菜单溢出图标变为黑色(应用程序有黑暗的操作栏).
更新 在我的nexus 5溢出图标和回收器视图行是固定的,但在Galaxy Tab 4溢出图标仍然是黑色.
更新2 如果您有空间距问题,请修复视图的布局参数(match_parent - > wrap_content),因为RecyclerView现在将根据其内容的大小自行调整大小.阅读此博客 http://android-developers.blogspot.am/2016/02/android-support-library-232.html
RecyclerView小部件为创建列表和网格以及支持动画提供了高级灵活的基础.此版本为LayoutManager API带来了令人兴奋的新功能:自动测量!这允许RecyclerView根据其内容的大小调整自身大小.这意味着现在可以使用以前不可用的方案,例如使用WRAP_CONTENT作为RecyclerView的维度.您会发现所有内置的LayoutManagers现在都支持自动测量.
由于此更改,请务必仔细检查项目视图的布局参数:现在将完全遵循先前忽略的布局参数(例如滚动方向中的MATCH_PARENT).
更新3 链接到描述操作栏问题201918中黑色图标 问题的问题
更新4 在帖子下看到我的回答,图标问题也解决了
android android-support-library android-recyclerview android-support-design
到目前为止,我一直在使用v23.0.1支持库,没有任何问题.现在当我切换到新的v23.1.0库时,我在抽屉布局中的小部件上得到一个空指针.
mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
TextView username = (TextView) mNavigationView.findViewById(R.id.username_textView);
// ^^^^^^^^ is now null when using new library
// which causes the following to fail
username.setText(mUser.getName());
Run Code Online (Sandbox Code Playgroud)
活动布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar" />
...
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer_items" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
drawer_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical">
<TextView
android:id="@+id/username_textView"
android:layout_width="match_parent"
android:layout_height="0dp" />
...
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
只需更改gradle文件以使用旧版本即可立即正常工作,因此我认为我的代码没有任何可怕的错误.我查看了 …
android android-support-library android-design-library android-support-design android-navigationview
我下面从这样的问题提示此创建一个按钮样式像材料设计建议.
但是,我需要通过继承Widget.AppCompat.Button.Colored样式和设置radius参数来更改角半径并且无法这样做.
我怎么能有相同的风格,但有圆角?
android android-button android-support-library material-design android-support-design
我已经展示了我的底部布局,其峰值高度设置为100dp.但是,如何限制我的底页仅扩展到500dp?这是我的示例布局:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator"
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">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
<android.support.v4.widget.NestedScrollView
android:id="@+id/design_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
app:behavior_hideable="true"
app:behavior_peekHeight="100dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="5dp"
android:background="#e444ff" />
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="5dp"
android:background="#e444ff" />
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="5dp"
android:background="#e444ff" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_margin="@dimen/activity_horizontal_margin"
app:layout_anchor="@+id/design_bottom_sheet"
app:layout_anchorGravity="top|right|end"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
除了我的问题,我怎么能禁止用户上下拖动底部纸张?
我目前FrameLayout在CoordinatorLayoutAndroid设计支持库中遇到问题,而我在创建选项卡时遵循了这篇文章中的说明.
基本上大多数事情按预期工作,容器碎片被充气到FrameLayout他们的标签 - 片段被相关地添加到ViewPageras标签(需要它这样,因为我有许多片段,应该重用布局).
我挣扎的问题是,在FrameLayout(并且结果也制表片段)消耗整个屏幕高度,使其重叠的Toolbar和TabLayout.为了可视化问题,我创建了以下图像:
基本布局与CoordinatorLayout,Toolbar和TabLayout:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include layout="@layout/toolbar" />
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
片段使用的单独布局膨胀为container:
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
Run Code Online (Sandbox Code Playgroud)
所有片段都被我的BaseFragment类夸大了(在SO调用的另一个帖子上inflater.inflate(getLayoutRes(), null);引发同样问题的问题)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(getLayoutRes(), container, false); …Run Code Online (Sandbox Code Playgroud) android android-layout android-fragments android-support-design
我正在尝试隐藏我的工具栏,当我滚动我的文本和图像与内容,这里我使用scrollView获取滚动内容时,当我滚动内容如何隐藏工具栏请任何人告诉我如何获得
这是我的XMl代码
content_main.XML
<android.support.v4.widget.NestedScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:paddingTop="?android:attr/actionBarSize"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="@+id/textone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="23dp"
android:textStyle="bold"
android:text="hello world jheds sdjhs jds sjbs skjs ksjs kksjs ksj sdd dskd js sk "/>
<ImageView
android:id="@+id/imge"
android:layout_width="match_parent"
android:layout_height="250dp"
android:src="@drawable/imag_bg"/>
<TextView
android:id="@+id/texttwo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Pretty good, the Toolbar is moving along with the list and getting back just as we expect it to. This is thanks to the restrictions that we put …Run Code Online (Sandbox Code Playgroud) android android-support-library android-toolbar android-support-design
使用Android> = 5.0时,
Drawable d = getResources().getDrawable(R.drawable.icon)
Run Code Online (Sandbox Code Playgroud)
正确解析XML并返回有效的drawable.但是当使用新的Vector Drawable支持库(版本23.4,Gradle 2.1.2)时,此代码在Android 4下崩溃.
android.content.res.Resources $ NotFoundException
...
引起:org.xmlpull.v1.XmlPullParserException:二进制XML文件行#2:无效的drawable标签向量
解决方案是使用
Drawable d = VectorDrawableCompat.create(getResources(), R.drawable.icon, null);
Run Code Online (Sandbox Code Playgroud)
但是,如果资源不是矢量资源,则会崩溃:
java.io.FileNotFoundException:损坏的XML二进制文件
那么什么样的代码已经被代替的第一线,使其适用于Android 4和Android 6与向量和非向量绘图资源 - 例如在在Android 5.0以上版本的项目中使用该行的所有情况?支持库文章未提及执行此迁移的方法
java android android-support-library android-support-design android-vectordrawable