我有一个相当典型的List功能,使用CoordinatorLayout,AppBarLayout,SwipeRefreshLayout和RecyclerView -
当RecyclerView有足够的内容滚动时,页面似乎很好.当RecyclerView为空或者没有足够的内容可以滚动时,行为是AppBarLayout子节点app:layout_scrollFlags="scroll|enterAlwaysCollapsed"将继续滚动 - 这看起来很奇怪.
当NestedScrollView为空时,有没有办法阻止AppBarLayout子项滚动?
<?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.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:elevation="4dp">
<LinearLayout
android:id="@+id/eventHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="@color/green"
android:orientation="horizontal"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="scroll|enterAlwaysCollapsed"
android:textColor="@color/white"
android:textSize="15sp"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeToRefresh"
android:layout_width="match_parent"
android:layout_gravity="fill_vertical"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:dividerHeight="0dp"
android:layout_gravity="fill_vertical"
android:drawSelectorOnTop="true"
android:listSelector="@drawable/selector_ripple_grey_transparent"
android:scrollbars="vertical"/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
<TextView
android:id="@+id/noData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="16dp"
android:text="@string/no_data_available"
android:textSize="17sp"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud) 我在A里面有三个按钮CollapsingToolbarLayout。展开后,其想法是修改正在显示的图库上的过滤器,或弹出一个编辑对话框。我得到的结果不一致-这些按钮只是间歇地响应单击。
最终,我意识到问题在于可点击区域比视图的客户区域小得多。在水平方向上,它们看起来很正常,但是在垂直方向上,可单击区域比按钮短得多。在模拟器中,我可以非常精确地了解范围:
您通常可以从左到右触摸它们,但是从上到下是错误的。
我一直在尝试从文档,官方指南,在线教程和开放源代码示例的各种摘要中拼凑出这种布局。我不完全了解所有精美的支持/设计布局是如何协同工作的,或者所有组合配置属性在组合时究竟能做什么,所以完全有可能通过简单更改一个或两个属性来解决。这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="?android:actionBarSize"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:contentScrim="?attr/colorPrimary"
android:background="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
android:theme="@style/Widget.Design.CollapsingToolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="32dp"
android:paddingBottom="64dp"
android:fitsSystemWindows="true"
app:layout_collapseMode="none"
android:background="@android:color/transparent"
android:orientation="horizontal">
<ImageButton android:id="@+id/btnTags"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_weight="0.3"
android:src="@drawable/ic_tag"
android:tint="?android:attr/buttonTint"
android:background="@drawable/ripple" />
<ImageButton android:id="@+id/btnAlbums"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_weight="0.3"
android:src="@drawable/ic_albums"
android:tint="?android:attr/buttonTint"
android:background="@drawable/ripple" />
<ImageButton android:id="@+id/btnNewAlbum"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_weight="0.3"
android:src="@drawable/ic_new_album"
android:tint="?android:attr/buttonTint"
android:background="@drawable/ripple" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarMain"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:title="@string/app_name"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/LouvreTheme.ToolbarStyle"/> …Run Code Online (Sandbox Code Playgroud) android android-layout material-design android-design-library
情况:我的布局中有一些自定义组件.我有一个共同的布局框架,我在我的Activity基类中onCreate()加载,然后使用inflater在我的实现中加载我的内容布局,将根设置为主布局的内容列.
问题:当我获取对视图的引用时,要实际提取用户的输入,Activity.findViewById()返回null.这或许是一个线索,我在布局中的CheckBox和Button不会返回null; 我获得了对小部件的有效引用.
我尝试过的事情:我知道我正在正确加载和扩展布局xml,因为一切都显示出来了,同一布局中的标准视图可以通过ID找到.我可以与我的视图交互并将内容放入它们和所有内容中,但我无法在代码中获得对它们的引用.
我多次尝试清理项目.R.id是新鲜的和最新的.
我检查了控制台和错误日志,并且没有报告UI/XML错误.
我尝试获取我为此活动加载的内容的根布局的句柄,并调用View.findViewById()以获取我的引用,并返回null.如果我在调试器中检查布局,我可以向下钻取并查找我的视图mChildren.
也许是另一个线索:
public VideoChooser(Context pCtxt, AttributeSet pAttrs)
{
super(pCtxt, pAttrs);
Log.d("VideoChooser", "Expected ID: " + R.id.vchShareVids + " | actual: " + getId());
}
Run Code Online (Sandbox Code Playgroud)
将导致以下输出:
DEBUG/VideoChooser(10372): Expected ID: 2131296271 | actual: 268435456
分配给View的ID与ID中的ID不匹配R.id!那为什么会这样?我知道它正在加载android:id属性,否则它将是-1(View.NO_ID).
通用布局框架:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:foo="http://schemas.android.com/apk/res/com.foo"
android:id="@+id/common_frame" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<!-- top banner -->
<LinearLayout …Run Code Online (Sandbox Code Playgroud) 我的类层次结构中的继承和方法解析存在一个奇怪的问题.该代码正在使用clang ++ 5.0进行编译-O0.我有两个类,所以:
class PrintBase
{
protected:
static wstring_convert<codecvt_utf8<wchar_t>> sConverter;
public:
virtual void PrintChar(wchar_t ch) = 0;
inline void PrintChar(char ch)
{
PrintChar(sConverter.from_bytes(ch)[0]);
}
virtual void PrintString(const wstring& str) = 0;
inline void PrintString(const string& str)
{
PrintString(sConverter.from_bytes(str));
}
};
class Print: public PrintBase
{
public:
virtual void PrintChar(wchar_t ch) override;
virtual void PrintString(const wstring& str) override;
};
void Print::PrintChar(wchar_t ch)
{
// do stuff
}
void Print::PrintString(const wstring& str)
{
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
如果我构造一个Print实例Print* pnt …