Hos*_*uri 8 android visibility show-hide relativelayout android-view
我想创建一个活动,如照片中提到的......一旦按下最大化按钮,我希望它成为活动的全屏,第1部分变为最小化,再次当我按下恢复按钮时我想要它成为第一状态:能够看到第1部分和第2部分......
我想如果我们放两个布局就有可能吗?不是吗?请参考资源来帮助我解决这个问题,或者向我展示实现解决方案的代码.

Die*_*mar 13
第一部分和第二部分应该采用自己的布局.之后,玩visilibity每个布局的属性.特别是要隐藏任何视图而不继续占用其空间,请使用gonevisibility属性的值.
好的,我走了.下面是一个如何隐藏/显示分组视图的完整示例.
main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/viewsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextBox One" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="TextBox Two" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="TextBox Three" />
</LinearLayout>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Hide" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
活动
public class MyActivity extends Activity implements OnClickListener {
private boolean viewGroupIsVisible = true;
private View mViewGroup;
private Button mButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mViewGroup = findViewById(R.id.viewsContainer);
mButton = findViewById(R.id.button);
mButton.setOnClickListener(this);
}
@Override
public void onClick(View button) {
if (viewGroupIsVisible) {
mViewGroup.setVisibility(View.GONE);
mButton.setText("Show");
} else {
mViewGroup.setVisibility(View.VISIBLE);
mButton.setText("Hide");
}
viewGroupIsVisible = !viewGroupIsVisible;
}
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助 ;)
| 归档时间: |
|
| 查看次数: |
17081 次 |
| 最近记录: |