我正在开发一个应用程序。它使用主布局。。
在它中,我使用相对布局,我有4个按钮。
按钮1、按钮2、按钮3和按钮4
因此,基于用户凭据和功能,我隐藏了一些按钮。例如
管理员可以查看的所有按钮
按钮2和3对于用户帐户是隐藏的。所以当用户登录时,我只显示按钮1和按钮4。
但我想重新排列UI外观。
目前,当按钮2和3被隐藏时,在屏幕上查看时,按钮1和4之间有很大的空间。
当按钮2和3被隐藏时,我想把按钮1移到按钮3的位置(在UI上更靠近4)。从而在观看屏幕时看起来很好。
我不知道如何做到这一点。当一个按钮被隐藏时,请让我知道如何重新排列布局中的按钮
<RelativeLayout
android:id="@+id/Info_RelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip" >
<Button
android:id="@+id/Camera_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/division_LinearLayout"
android:background="@drawable/camera_selector" />
<Button
android:id="@+id/Favorite_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/GotoCamera_Button"
android:background="@drawable/favorite_btn_selector" />
<Button
android:id="@+id/Profile_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/Favorite_Button"
android:background="@drawable/profile_list_btn_selector" />
<Button
android:id="@+id/Info_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ProfileList_Button"
android:background="@drawable/camerainfo_selector" />
</RelativeLayout>
试着在按钮上使用setVisibility(View.GONE),而不是让它们不可见。当它们消失时,它们不会占用空间进行布局,这与它们只是不可见时不同。
尝试删除如下按钮:
ViewGroup layout = (ViewGroup) btnToRemove.getParent();
if(null!=layout) layout.removeView(btnToRemove);