FlexLayout icon indicating copy to clipboard operation
FlexLayout copied to clipboard

Flexlayout隐藏子控件之后,子控件仍然占用空间

Open dxp2020 opened this issue 8 years ago • 4 comments

我给子控件添加了属性 android:visibility="gone",结果控件隐藏了,但控件仍然占用了空间,效果是跟 android:visibility="invisible"一样的

dxp2020 avatar Oct 16 '17 03:10 dxp2020

能把具体的代码贴上来看一下吗

mmin18 avatar Oct 16 '17 03:10 mmin18

TextView android:id="@+id/tv_high_speed_charge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/add_charge" android:textColor="@color/color_999999" android:visibility="gone" app:layout_centerX="50%" app:layout_top="prev.bottom+15dp"

就比如说这个控件,隐藏之后仍然占用了空间

dxp2020 avatar Oct 16 '17 04:10 dxp2020

你们没有这种情况么

dxp2020 avatar Oct 17 '17 07:10 dxp2020

我试了一下好像没问题 fl

<?xml version="1.0" encoding="utf-8"?>
<com.github.mmin18.widget.FlexLayout
	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">

	<View
		android:layout_width="60dp"
		android:layout_height="60dp"
		android:background="#f00"
		app:layout_centerX="50%"
		app:layout_top="10dp"/>

	<TextView
		android:id="@+id/tv_high_speed_charge"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="tv_high_speed_charge"
		android:textColor="#fff"
		android:visibility="gone"
		app:layout_centerX="50%"
		app:layout_top="prev.bottom+15dp"/>

	<View
		android:layout_width="60dp"
		android:layout_height="60dp"
		android:background="#0f0"
		app:layout_centerX="50%"
		app:layout_top="tv_high_speed_charge.bottom"/>

	<Button
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:onClick="switchGone"
		android:text="switch"
		app:layout_centerX="50%"
		app:layout_centerY="50%"/>
</com.github.mmin18.widget.FlexLayout>
	public void switchGone(View v) {
		View g = findViewById(R.id.tv_high_speed_charge);
		g.setVisibility(g.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
	}

mmin18 avatar Oct 28 '17 12:10 mmin18