问题描述
在我的应用程序的布局,我有一个设置按钮....我们按下时,它会显示一些子菜单....当我们再次推它,它会隐藏所有的子菜单....样子扩展列表视图,但不完全一样....只是躲在/为了得到另一个观点一定的空间,取消隐藏菜单....我怎么能做到这一点?
in my application layout, i have a setting button....when we push it, it will show some sub menus....when we push it again, it will hide all sub menus....look like expandable listview, but not exactly like that....just hiding/unhiding menu in order to get some space for another views....how can i do that?
这里要说的是正是我想要做的截图
here is the screenshots that exactly what i want to do
的我的xml文件:
<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<EditText
android:id="@+id/Editsearch"
android:hint="Enter keyword..."
android:layout_alignParentLeft="true"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_toLeftOf="@+id/search"
android:layout_height="wrap_content" />
<ImageButton
android:id="@+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_search"
android:layout_alignParentRight="true" />
<Spinner
android:id="@+id/province"
android:layout_width="135dp"
android:layout_height="45dp"
android:layout_below="@+id/Editsearch"
android:layout_toLeftOf="@+id/setting"
android:textSize="12dip"
android:textStyle="bold"
android:background="@android:drawable/btn_default"
/>
<ImageButton
android:id="@+id/setting"
android:layout_width="wrap_content"
android:layout_height="45dip"
android:layout_below="@+id/Editsearch"
android:src="@drawable/button_setting"
android:layout_alignParentRight="true" />
<Spinner
android:id="@+id/Category"
android:layout_width="135dp"
android:layout_height="45dp"
android:text="Category"
android:layout_below="@+id/Editsearch"
android:layout_alignParentLeft="true"
android:background="@android:drawable/btn_default" />
<!-- Job Category title-->
<TextView
android:id="@+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:typeface="serif"
android:textSize="13dip"
android:layout_below="@+id/province"
android:layout_gravity="center"
android:text="Total Job : 1982"
android:textStyle="bold" />
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Title"
android:listSelector="@drawable/list_selector" />
</RelativeLayout>
感谢提前
推荐答案
这是非常简单的。
只要将这些3个按钮的布局和设置隐藏/取消隐藏按钮,点击该布局走了/可见光的知名度。
It is very simple.Just place those 3 buttons in a layout and set the visibility of that layout to gone/visible on click of hide/unhide button.
编辑:
它会像把你的纺纱厂,你想隐藏/取消隐藏在布局,并为它提供一个ID。
It will be like put your spinners which you like to hide/unhide in a layout and provide an ID for it.
<ImageButton
android:id="@+id/setting"
android:layout_width="wrap_content"
android:layout_height="45dip"
android:layout_alignParentRight="true"
android:layout_below="@+id/Editsearch"
android:src="@drawable/button_setting" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
**android:id="@+id/submenu_layout"**
android:layout_below="@+id/Editsearch"
>
<Spinner
android:id="@+id/category1"
android:layout_width="135dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:background="@android:drawable/btn_default"
android:text="Category" />
<Spinner
android:id="@+id/category2"
android:layout_width="135dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_below="@id/category1"
android:background="@android:drawable/btn_default"
android:text="Category" />
<Spinner
android:id="@+id/category3"
android:layout_width="135dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/category2"
android:background="@android:drawable/btn_default"
android:text="Category" />
</RelativeLayout>
然后用这个ID来拿在code此布局的参考。
Then use this id to take the reference of this layout in your code.
RelativeLayout submenuLayout = (RelativeLayout) findViewById(R.id.submenu_layout);
编辑2:
在设定的ImageButton那的OnClick:
After that OnClick of setting imageButton :
if(submenuLayout .getVisibility() == View.VISIBLE)
submenuLayout .setVisibility(View.GONE);
else
submenuLayout .setVisibility(View.VISIBLE);
这篇关于Android的扩展菜单(隐藏/取消隐藏菜单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!