如何添加布局 [英] How to add a Layout

查看:227
本文介绍了如何添加布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想一个布局添加到我的活动。

我有一个的FrameLayout,我添加一个SurfaceView至今。

现在我想通过它添加另一个布局作为菜单所以当我点击我的面查看我将它设置为可见的按钮。

此布局应包含一个TextView的,应当滚动

1:什么是这种方法的最佳LAyoutout的事情吗?我想在这里我想补充一个字符串列表视图动态

2:我怎样才能在code ++实现这个

它应该是:

滚动。
应该是具有一定规模:一半屏幕宽度的一半的screenHeight的
所以它也应当是在位置屏幕宽度/ 4和screenHeight / 4
要做到这一点,我可以把我的mainThread内这些参数连接到surfaceview所以我必须在像素格式是没有问题的媒体链接所需要的参数。
当用户点击该视图之外应松专注所以我surfaceView得到Focusagain和布局设置了。

因此​​,它应该是这样的:

用户点击该按钮可显示菜单
现在,用户可以通过滚动菜单
当他presses的后退按钮或外部视图应该关闭自己
当存在应该显示它应附加到布局的新文本要准备在用户再次点击按钮的下一次要显示

感谢您


解决方案

  

1:什么是这种方法的最佳LAyoutout的事情吗?我想在这里我想补充Textviews一个ListView动态


这听起来不错,你可与的ListView RecyclerView 去。你基本上是不加入的TextView 取值动态,为您创造一个适配器,会做处理创造和为贵的意见回收。


  

2:我怎样才能在code ++实现这个


创建一个 DialogFragment ,它是这样的对话与逻辑的最佳人选。它的生命周期通过 FragmentManager 处理,所以你不会有屏幕旋转等问题。它允许你设置任何你需要的布局,就像任何其他片段。它将被放置在中心为您服务,让您不必手动处理的。只需设置你想要的对话框的大小和它看起来完美的。


  

当用户点击视图之外应该失去焦点,这样我surfaceView得到Focusagain和布局设置了。


我真的不明白这一点。当用户触摸外,你是否需要减肥的焦点,但对话应该的不可以关闭?如果是,那么这是已经在这里回答:

允许外部触摸查询DialogFragment

如果对话框应该关闭,你没有实现任何东西,它就像在默认情况下。

Hello I want to add a LAyout to my Activity.

I have a FrameLayout where I add a SurfaceView so far.

Now I want to add another Layout as a menu over it so when I click a Button on my Surface View I set it to be Visible.

This layout should contain one Textview and should be scrollable

1: What is the best LAyoutout thing for this approach? I thought of a Listview where I add Strings dynamically

2: How can I achieve this in Code?

It should be:

Scrollable. Should be a certain Size: Half of the screen width and half of the screenHeight So it also should be at the position screenWidth/4 and screenHeight/4 To achieve this I can set these parameters inside my mainThread that is attached to the surfaceview so I have the parameters needed allready in Pixel format that's no Problem. It should loose the Focus when the User taps outside of the view so my surfaceView gets the Focusagain and set the LAyout to Gone.

So it should go like this:

User taps the button to display the menu Now the User can scroll through the Menu When he presses the Backbutton or outside of the View It should close itself When there is a new Text that should be displayed it should be attached to the layout to be ready to be displayed at the next time the user clicks the button again

Thank you

解决方案

1: What is the best LAyoutout thing for this approach? I thought of a Listview where I add Textviews dynamically

That sounds good to me, you can go with either ListView or RecyclerView. You are basically not adding TextViews dynamically, you create an adapter that will do handle creating and recycling of views for you.

2: How can I achieve this in Code?

Create a DialogFragment, it's the best candidate for such dialogs with logic. Its lifecycle is handled via FragmentManager, so you won't have issues on screen rotations and so on. It allows you setting whatever layout you need just like any other Fragment. It will be placed in the center for you, so you don't have to handle that manually. Just set the size of the dialog you want and it will look perfect.

It should loose the Focus when the User taps outside of the view so my surfaceView gets the Focusagain and set the LAyout to Gone.

I don't really get this one. When user touches outside, do you need to lose the focus but the dialog should not be closed? If yes, then this is already answered here:

Allow outside touch for DialogFragment

If the dialog should be closed, you don't have to implement anything, it works like that by default.

这篇关于如何添加布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆