1
這是當我爲我的空視圖設置'視圖'時發生的情況。 (整個屏幕,而不是ListView控件的尺寸內的空視圖適合SetEmptyView不適合他的父母(列表視圖)
我想適合我的藍色區域內空的觀點(見圖片)。 enter image description here
empty_items
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bdbdbd">
<ImageView
android:id="@+id/image1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:background="@mipmap/ic_inf"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:contentDescription="information">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="168dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="SIN NADA POR MOSTRAR"
android:textAlignment="center"
android:textSize="32sp"
android:textStyle="bold"
android:textColor="#757575"
android:id="@+id/infoMsgTextView"
android:layout_gravity="center_horizontal|bottom"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_marginTop="224dp"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"/>
sales_fragment.xml - 我想設置空視圖的listview片段。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fbutton="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:htext="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
tools:context=".controler.SalesFragment"
android:visibility="visible"
>
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="165dp"
android:layout_gravity="center"
android:background="#144257"
android:id="@+id/relativeLayout"
android:layout_below="@+id/tvClient"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:background="@drawable/roundedshadow_et"
android:ems="10"
android:id="@+id/discountEditText"
android:elegantTextHeight="false"
android:hint="@string/discountHint"
android:textColorHint="#FFFF"
android:textColor="#FFFF"
android:textAlignment="center"
android:layout_alignTop="@+id/etPrice"
android:layout_toLeftOf="@+id/etPrice"
android:layout_toStartOf="@+id/etPrice"/>
<AutoCompleteTextView
android:layout_width="300dp"
android:background="@drawable/roundedshadow_et"
android:layout_height="60dp"
android:singleLine="true"
android:scrollHorizontally="true"
android:id="@+id/productAutoCompleteTextView"
android:hint="@string/product"
android:textColorHint="#FFFF"
android:layout_gravity="center"
android:textAlignment="center"
android:textColor="#ffff"
android:visibility="visible"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:background="@drawable/roundedshadow_et"
android:ems="10"
android:id="@+id/amountEditText"
android:elegantTextHeight="false"
android:textAlignment="center"
android:textColor="#FFFF"
android:textColorHint="#FFFF"
android:hint="@string/amountHint"
android:layout_alignTop="@+id/discountEditText"
android:layout_alignLeft="@+id/productAutoCompleteTextView"
android:layout_alignStart="@+id/productAutoCompleteTextView"/>
<info.hoang8f.widget.FButton
android:layout_width="70dp"
android:layout_height="wrap_content"
fbutton:buttonColor="#144257"
fbutton:shadowColor="#0e2e3c"
fbutton:shadowEnabled="true"
fbutton:shadowHeight="5dp"
fbutton:cornerRadius="5dp"
android:textColor="#ffff"
android:textAlignment="center"
android:text="@string/addProduct"
android:id="@+id/addProductBtn"
android:layout_below="@+id/discountEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:background="@drawable/roundedshadow_et"
android:ems="10"
android:id="@+id/etPrice"
android:elegantTextHeight="false"
android:textAlignment="center"
android:textColor="#FFFF"
android:textColorHint="#FFFF"
android:hint="@string/priceHint"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/productAutoCompleteTextView"
android:layout_alignEnd="@+id/productAutoCompleteTextView"/>
</RelativeLayout>
<com.hanks.htextview.HTextView
android:id="@+id/tvClient"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#144257"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="15sp"
htext:animateType="anvil"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAlignment="center"/>
<com.hanks.htextview.HTextView
android:id="@+id/tvPrice"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#144257"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="15sp"
htext:animateType="anvil"
android:textAlignment="center"
android:layout_below="@+id/relativeLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/sale_floating_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:menu_animationDelayPerItem="55"
fab:menu_backgroundColor="@color/fbutton_color_transparent"
fab:menu_buttonSpacing="0dp"
fab:menu_colorNormal="#e040fb"
fab:menu_colorPressed="#4d0359"
fab:menu_colorRipple="#99d4d4d4"
fab:menu_fab_label="Opciones de venta"
fab:menu_fab_size="normal"
fab:menu_icon="@mipmap/shopping_cart"
fab:menu_labels_colorNormal="#333"
fab:menu_labels_colorPressed="#444"
fab:menu_labels_colorRipple="#66efecec"
fab:menu_labels_cornerRadius="3dp"
fab:menu_labels_ellipsize="none"
fab:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
fab:menu_labels_margin="0dp"
fab:menu_labels_maxLines="-1"
fab:menu_labels_padding="8dp"
fab:menu_labels_position="left"
fab:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
fab:menu_labels_showShadow="true"
fab:menu_labels_singleLine="false"
fab:menu_labels_textColor="#f2f1f1"
fab:menu_labels_textSize="15sp"
fab:menu_openDirection="up"
fab:menu_shadowColor="#66aff198"
fab:menu_shadowRadius="4dp"
fab:menu_shadowXOffset="1dp"
fab:menu_shadowYOffset="4dp"
fab:menu_showShadow="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
>
<com.github.clans.fab.FloatingActionButton
android:id="@+id/floating_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/add_tag"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/floating_checkout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/checkout"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvPrice">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:longClickable="true"
android:id="@+id/lvCart"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
SalesFragment.java @Override 公共視圖onCreateView(LayoutInflater充氣,最終容器的ViewGroup, 捆綁savedInstanceState) { //充氣的佈局該片段
View view = inflater.inflate(R.layout.fragment_sales, container, false);
neverEmptyListView = (ListView) view.findViewById(R.id.lvCart);
ViewGroup headerView = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.header_row_layout, neverEmptyListView, false);
neverEmptyListView.addHeaderView(headerView);
View emptyView = getActivity().getLayoutInflater().inflate(R.layout.empty_items, null);
emptyMsg = (TextView) emptyView.findViewById(R.id.infoMsgTextView);
emptyMsg.setText("Agregue productos para la venta");
getActivity().addContentView(emptyView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
neverEmptyListView.setEmptyView(emptyView);
items = new ArrayList<String>();
lvAdapter = new ListViewAdapter
(getContext(), R.layout.row_layout, R.id.description, items);
neverEmptyListView.setAdapter(lvAdapter);
刪除此行然後檢查:getActivity()addContentView(emptyView,新ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)); – Vickyexpert
當我刪除該行時,即使沒有項目,從我的列表視圖消失的空視圖。 –