Android:在线性布局之上放置一些东西
我想做的是当按下按钮时在“2”(第二个 LinearLayout)顶部显示一个“框架”(或新布局)。我该怎么做呢?预先创建它并在未按下按钮时以某种方式隐藏它?
我有这种类型的布局:
XML:
<LinearLayout>
<LinearLayout>
</LinearLayout>
<LinearLayout>
//here would be another view, only shown when a button is clicked
<ViewFlipper>
</ViewFlipper>
</LinearLayout>
<RelativeLayout
</RelativeLayout>
</LinearLayout>
What I want to do is show a "frame" (or new layout) on top of "2" (second LinearLayout), when a button would be pressed. How should I do it? Precreate it and make it somehow hidden if button not pressed?
I have this type of layout:
XML:
<LinearLayout>
<LinearLayout>
</LinearLayout>
<LinearLayout>
//here would be another view, only shown when a button is clicked
<ViewFlipper>
</ViewFlipper>
</LinearLayout>
<RelativeLayout
</RelativeLayout>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
FrameLayout
来显示覆盖另一个view
的view
。您可以将视图保持为INVISIBLE
或在 xml 中使用GONE
,然后在单击Button
时使其可见。Use
FrameLayout
to showview
over-lapping anotherview
. You can keep the view asINVISIBLE
or usingGONE
in the xml and then just make it visible when theButton
is Clicked.是的...您应该在 xml 中准备它并给它一个 id。然后您可以使用
mLinearLayout.setVisibility(View.GONE);
和mLinearLayout.setVisibility 轻松管理其在按钮单击时的可见性(View.VISIBLE);
就像:Yes...you should prepare it in xml and give it an id.then you can easily manage its visibility on button click using
mLinearLayout.setVisibility(View.GONE);
andmLinearLayout.setVisibility(View.VISIBLE);
like:这里有两个选择:
正如您所说,预先创建布局并将可见性设置为 Visibility_Gone 为布局最初不显示,将 Visibitlity 设置为 View.Visible 以显示布局。
另一种方法是动态创建视图,并添加到指定索引上的父级,例如添加到线性布局使用之上:
Here you have two options:
As you said pre-create layouts and set visibility to Visibility_Gone to layouts initially, not to be shown, set Visibitlity to View.Visible to display the layouts.
Another approach is to create views dynamically, and adding to parent on specified index, like to add on top of linearlayout use:
如果您想在单击按钮时显示任何视图,请首先将该视图放入 xml 中并使其可见性消失,然后在单击按钮时使其可见。我已将 imageview 放入您的代码中,其可见性设置为消失,因此它不会在布局中显示。
为了使图像视图可见,
If you want to show any view on button click then first put that view inside xml and make its visibility gone, and on button click make it visible. I have put imageview inside your code which visibility is set as gone so it wont show in layout.
For making image view visible,