布局
<ViewStub
android:id="@+id/place_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="56dp"
android:layout="@layout/empty_placeholder" />
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content_rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/mdtp_white"
android:clickable="true"
android:focusable="true" //解决viewStub覆盖的布局可以点击的bug
android:gravity="center">
<ImageView
android:id="@+id/ic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/deal_empty" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ic"
android:ellipsize="end"
android:gravity="center"
android:maxLines="2"
android:text="@string/empty"
android:textAppearance="@style/TextAppearance.Teambition.T1" />
</RelativeLayout>
kotlin中使用
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
......
placeHolder = view.findViewById(R.id.place_holder)
......
}
private fun showEmptyView() {
placeHolder.visibility = View.VISIBLE//设置visibility ,内部会在没有inflate()执行inflate()的
view?.findViewById<TextView>(R.id.msg)?.text = String.format(getString(R.string.empty_msg), getString(R.string.deal))
}
private fun hideEmptyView() {
placeHolder.visibility = View.GONE
}
网友评论