这是代码.
<?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/main"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/mytoolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="@string/app_name"
app:layout_collapseMode="pin"
app:theme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/main_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_collapseMode="none"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!--<android.support.v4.widget.NestedScrollView-->
<!--android:id="@+id/nestedscroll"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:fillViewport="true"-->
<!--android:scrollbars="horizontal"-->
<!--app:layout_behavior="@string/appbar_scrolling_view_behavior">-->
<android.support.v4.view.ViewPager
android:id="@+id/main_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<!--</android.support.v4.widget.NestedScrollView>-->
<android.support.design.widget.FloatingActionButton
android:id="@+id/main_fab"
android:layout_margin="16dp"
android:src="@android:drawable/ic_media_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/main_viewpager"
app:layout_anchorGravity="bottom|end"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
问题:
1)工具栏不可见.
2)折叠工具栏根本不会崩溃.[已解决]
3)如果放入nestedScrollView内,Viewpager和FAB也不可见.[解决了]
更多细节:
Viewpager片段的布局将Linearlayout作为root,内部具有recyclerview.
根据代码,一切似乎都没问题.无法理解缺少的东西.协调器布局和折叠工具栏如何协同工作的一个很好的解释也确实有帮助.
android android-layout android-xml android-coordinatorlayout android-collapsingtoolbarlayout
我正在使用一种扩展的服务MediaBrowserServiceCompat,并且还MediaSessionCompat.Callback()使用了它的重写方法onPlayFromMediaId().
在单击recyclelerview项目时具有recyclelerview的片段内部,将调用以下代码.从图像中可以看出,mediaId除了songBundle值之外,还有传递给onPlayFromMediaId()方法.
奇怪的是,在Service类中,playFromMediaId()方法被覆盖,它只接收字符串变量的值,mediaId而songBundle神奇地变为空.(注意 - 用于放置和获取parcelable的键也是相同的.piplable songsVO是实现Parcelable接口的POJO .)
除了这个我注意到的另一个有趣的事情,当我返回到onPlayFromMediaId()已经执行后调用后面的片段并检查每个变量的值,除了mediaId每个其他变量都变为null.
RecyclerAdapter类
class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.layout_song_item, parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) { …Run Code Online (Sandbox Code Playgroud) android android-service android-mediaplayer mediabrowserservicecompat
使用java,动态创建一个控件,我们使用类似的东西
TextView textview=new TextView(getApplicationContext());
如何在Kotlin做同样的事情?var textview = TextView
不行,也不行var textview as TextView
不幸的是,甚至没有遇到任何关于Android的好的kotlin教程.
更新 - 实际上我正在尝试使用自定义布局创建动态列表视图.