我制作了一个h_shape = (3, 3)
device = Test_device(h_shape)
k = 1.3
locn = (1, 1)
device.get_H(k, locn=locn)
print device.h
,其中包含DialogFragment
,并且ViewPager
包含ViewPager
,其中包含Fragments
。我面临的问题是Recyclerview
中只有一项,而Recyclerview
中的项目大小是错误的。
这是我的Recyclerview
DialogFragment
这是class StickerSelectorPopup: DialogFragment(), StickerPickerAdapter.Listener {
private lateinit var mAdapter: FeedFragment.Adapter
private lateinit var mViewPager: ViewPager
private lateinit var mTabs: TabLayout
private var isFirstTime = true
private var mUserUid = ""
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val mView = inflater.inflate(R.layout.dialog_view_sticker_tab, container, false)
mViewPager = mView.findViewById(R.id.viewpager)
mTabs = mView.findViewById(R.id.result_tabs)
mAdapter = FeedFragment.Adapter(childFragmentManager)
return mView
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mAdapter.addFragment(StickerPickerFragment.newInstance(mutableListOf("chat.gif", "fhere.gif", "hai.gif", "sedih.gif"), 2, this@StickerSelectorPopup, "gabut_woman"), "Gabut Woman")
mAdapter.addFragment(StickerPickerFragment.newInstance(mutableListOf("8.gif"), 2, this@StickerSelectorPopup, "gabut_man"), "Gabut Man")
mViewPager.adapter = mAdapter
mTabs.setupWithViewPager(mViewPager)
}
}
加载的Fragment
ViewPager
这是class StickerPickerFragment : Fragment() {
private var mListSticker = mutableListOf<String>()
private var mStickerUid = 0
private var mFolder = ""
private lateinit var mListener: StickerPickerAdapter.Listener
private lateinit var mRecycleView: RecyclerView
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val v = inflater.inflate(R.layout.fragment_sticker_picker, container, false)
mRecycleView = v.findViewById(R.id.adStickerPickerRvMain)
mRecycleView.setHasFixedSize(true)
mRecycleView.layoutManager = LinearLayoutManager(context!!)
mRecycleView.adapter = StickerPickerAdapter(mFolder, mStickerUid, mListener)
(mRecycleView.adapter as StickerPickerAdapter).addAll(mListSticker)
return v
}
}
xml
DialogFragment
此片段由ViewPager XML加载
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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="wrap_content"
android:orientation="vertical">
<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.design.widget.TabLayout
android:id="@+id/result_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:tabIndicatorColor="@color/colorPrimary"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/colorWhite"
app:tabTextColor="@color/gray_btn_bg_pressed_color"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="300dp"
/>
</LinearLayout>
此项目<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
tools:context=".ui.stickerpicker.StickerPickerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/adStickerPickerRvMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/amber_100"/>
</LinearLayout>
xml
RecyclerviewAdapter
仅适用于1个项目。如果有多个项目,则仅显示第一个项目,并且项目视图大小不正确。
蓝色是项目适配器的背景 黄色是片段中Recyclerview的背景