我正在使用新的Android支持设计库.我已经在Android Developer Blogspot上关注了演示,除了我使用RecyclerView的片段而不是将它们放在同一个xml中.
这是我的activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
>
<android.support.design.widget.CoordinatorLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/toolbar"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<fragment
android:id="@+id/navigation_drawer"
android:layout_marginTop="?android:attr/actionBarSize"
android:name="aungkyawpaing.yangonuniversity.Fragments.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start|left"
tools:layout="@layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
这是toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<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/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
And this is the fragment where it has RecyclerView
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/department_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Run Code Online (Sandbox Code Playgroud)
我在gradle中添加了最新的支持库依赖项.我看到另一个人说它不起作用,因为他在片段中使用了列表视图,但我正在使用RecyclerView.
在关注liuguangqiang的样本甚至Chris Bane的 Android设计支持库的cheesesquare样本时,工具栏间距似乎存在问题,就像在图像中一样.

这是我的activity.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: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="192dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/header"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/scrollableview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
android:src="@drawable/ic_action_add"
app:layout_anchor="@+id/appbar"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我非常密切地关注了Chris Bane的样本.然而,这个问题只存在于Lollipop上,而它在Lollipop之前完全正常.
任何遇到相同问题或知道可能修复的人?
xml android android-appcompat androiddesignsupport android-collapsingtoolbarlayout
我对新的导航视图有几个问题.
1)滚动导航视图会滚动整个视图,但我只想让标题留在它的位置并滚动导航项.

2)要实现分频器黑白导航项目,我可以这样做:
<item
android:id="@+id/navigation_subheader"
android:title="@string/navigation_subheader">
<menu>
<item
android:id="@+id/navigation_sub_item_1"
android:icon="@drawable/ic_android"
android:title="@string/navigation_sub_item_1"/>
<item
android:id="@+id/navigation_sub_item_2"
android:icon="@drawable/ic_android"
android:title="@string/navigation_sub_item_2"/>
</menu>
</item>
Run Code Online (Sandbox Code Playgroud)
但如果没有副标题,它就不起作用.我试图给它一个空白字符串,但只留下一个垂直空格而不是副标题.我需要由分隔符分隔的导航项组,但没有子标题.
3)动态操作导航项.在此之前,我曾经使用垂直列表视图作为导航项.我只是将可见性设置为我不想要的任何导航项目.如何动态更改导航项?
android navigation-drawer android-design-library androiddesignsupport android-navigationview
我在android支持设计库中遇到了Snackbar的问题.奇怪的是,它只发生在我在调试模式下运行我的应用程序时,在发布模式下它完全可以正常工作.
有没有人对这个问题有所了解?它似乎是支持库中的一个错误.
码
using (var snackbar = Snackbar.Make(View, "Nieuwe order aangemaakt", Snackbar.LengthLong).SetAction("OK", v => { }))
snackbar.Show();
Run Code Online (Sandbox Code Playgroud)
例外
07-06 11:47:50.414 I/MonoDroid(13296):Java.Lang.ClassCastException:抛出了类型'Java.Lang.ClassCastException'的异常.07-06 11:47:50.414 I/MonoDroid(13296):at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()07-06 11:47:50.414 I/MonoDroid(13296):at OverAllField.XamarinAndroid.Fragments.Planning .PlanningFragment.FloatingActionButton_Click(object,System.EventArgs)[0x00001]在c:\ Development\Apps\FieldService-Tablet\OverAllF07-06 11:47:50.414 I/MonoDroid(13296):at Android.Runtime.JNIEnv.CallStaticObjectMethod( intptr,intptr,Android.Runtime.JValue*)[0x00064] /Users/builder/data/lanes/1502/24855232/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1301 07 -06 11:47:50.414 I/MonoDroid(13296):在Android.Support.Design.Widget.Snackbar.Make(Android.Views.View,Java.Lang.ICharSequence,int)07-06 11:47:50.414 I/MonoDroid(13296):在Android.Support.Design.Widget.Snackbar.Make(Android.Views.View,string,int)07-06 11:47:50.414 I/MonoDroid(13296):at OverAllField.XamarinAndroid.Fragments c:\ De中的.Planning.PlanningFragment.FloatingActionButton_Click(object,System.EventArgs)[0x00001] velopment\Apps\FieldService-Tablet\OverAllField.XamarinAndroid\OverAllField.Android\Fragments\Planning\PlanningFragment.cs:74 07-06 11:47:50.414 I/MonoDroid(13296):at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View)[0x0000d]在/Users/builder/data/lanes/1502/24855232/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View中. cs:1923 07-06 11:47:50.414 I/MonoDroid(13296):在/ Users/builder/data/lanes/1502 /中的Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_(intptr,intptr,intptr)[0x00011] 24855232/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:1888 07-06 11:47:50.414 I/MonoDroid(13296):at(包装动态) -method)object.84d16582-f149-4133-af10-0f21d61ca331(intptr,intptr,intptr)07-06 11:47:50.414 I/MonoDroid(13296):---托管异常堆栈跟踪结束--- 07- 06 11:47:50.414 I/MonoDroid(13296):java.lang.ClassCastException:android.widget.LinearLayout canno t被转换为android.support.design.widget.Snackbar $ SnackbarLayout 07-06 11:47:50.414 I/MonoDroid(13296):在android.support.design.widget.Snackbar.(Snackbar.java:119)07- 06 11:47:50.414 I/MonoDroid(13296):在android.support.design.widget.Snackbar.make(Snackbar.java:140)07-06 11:47:50.414 I/MonoDroid(13296):单声道. …
classcastexception xamarin.android snackbar android-snackbar androiddesignsupport
我想在导航视图标题的项目中添加onClickListener,例如更改TextView文本或为ImageView设置图像.
我有一个带有 Fragments 的 ViewPager,其中包含 RecyclerViews。CollapsingTollbarLayout 位于 ViewPager 上方。除了在 RecyclerView 上以编程方式滚动之外,一切都工作正常。然后 AppBarLayout 或 CollapsingToolbarLayout 没有响应。
这是我的基本布局 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"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_behavior="de.wackernagel.playball.ui.FlingBehaviour">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/collapsingToolbarLayout"
app:contentScrim="?attr/colorPrimary"
app:titleEnabled="false"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:contentDescription="@null"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/showdown"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/doubleActionBarSize"
android:minHeight="?attr/actionBarSize"
android:gravity="top"
app:titleMarginTop="14dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
android:layout_gravity="bottom"
app:tabTextColor="#BEFFFFFF"
app:tabSelectedTextColor="#FFFFFFFF"
app:tabContentStart="@dimen/keyline_2"
app:tabMode="scrollable" />
</android.support.design.widget.CollapsingToolbarLayout>
</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"/>
Run Code Online (Sandbox Code Playgroud)
我的目标是在像普通触摸滚动一样以编程方式滚动期间折叠 CollapsingToolbarLayout。
我这样做是通过
Activity get …Run Code Online (Sandbox Code Playgroud) android android-recyclerview androiddesignsupport android-collapsingtoolbarlayout
第一次使用com.android.support:design:23.1.1,并有一些问题让TabLayout工作.
我的应用程序基本上是这样设置的:
一个名为LandingActivity的主要活动,其中包含一个带有菜单项的DrawerLayout.
选择菜单项时,我将不同的片段加载到LandingActivity中的FrameLayout中.
一些加载的碎片应该在顶部显示标签,有些不应该.
我的问题是,在应该在顶部显示标签的Fragment上,它在导航栏中有额外的空间,就像它应该有标签一样,但没有任何显示.
码:
activity_landing.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The ActionBar displayed at the top -->
<include
layout="@layout/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' --> …Run Code Online (Sandbox Code Playgroud) android android-fragments material-design androiddesignsupport
使用BottomSheetBehavior来自谷歌的设计库,它看起来像默认行为是底片,以"盖"在同其他意见CoordinatorLayout,因为它扩大.我可以将类似FAB(或其他具有适当定义的视图CoordinatorLayout.Behavior)的东西锚定到工作表的顶部,并在工作表展开时将其向上滑动,这很好,但我想要的是将视图"折叠"为底部页面展开,显示出视差效果.
谷歌地图中的这种效果类似于我正在寻找的效果; 它以视差效果开始,然后切换回只有在达到某个滚动位置时底部"覆盖"地图:
我试过的一件事(虽然我从一开始就怀疑它不起作用),是在onSlide我的调用中以编程方式设置上部视图的高度BottomSheetBehavior.BottomSheetCallback.这有点成功,但运动并不像谷歌地图那样顺畅.
如果有人知道效果是如何完成的,我会非常感激!
我正在尝试 android 上的新材料设计组件,例如底部应用栏,但我发现每个 MDC 都存在于 android 设计支持库中,但也存在于另一个被调用com.google.android.material的库中,并且代码几乎相同(在设计库中,代码与另一个不同),那么这两个库之间有什么区别?
android android-studio android-design-library androiddesignsupport
我正在尝试在我的主要项目中实现底部模式表。我在一个演示项目中成功地做到了。但是当我将相同的结构应用于我的主项目时,应用程序崩溃并出现以下错误:
android.view.InflateException:二进制 XML 文件第 40 行:无法膨胀行为子类 android.support.design.widget.BottomSheetBehavior 由:java.lang.RuntimeException:无法膨胀行为子类 android.support.design.widget.BottomSheetBehavior
AndroidRuntime:引起:java.lang.ClassNotFoundException:在路径上找不到类“android.support.design.widget.BottomSheetBehavior”:DexPathList[[zip file“/data/app/com.example...... ..]]]
我尝试了之前app:layout_behavior="@string/bottom_sheet_behavior"在我的 xml 中所述的内容,但没有奏效。
在演示项目中,底部工作表在嵌套父视图中正常工作。
我的主要项目依赖项是 -(添加到 app build.gradle)
def lifecycle_version = "2.1.0-alpha02"
def room_version = "2.1.0-alpha04"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'me.relex:circleindicator:2.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
Run Code Online (Sandbox Code Playgroud) android android-design-library androiddesignsupport bottom-sheet