如何使用LayoutInflater / ViewStub用于覆盖 [英] How to use LayoutInflater / ViewStub for an overlay

查看:208
本文介绍了如何使用LayoutInflater / ViewStub用于覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我其实并不是很自信与编程改变意见,我有以下问题:

As I am actually not very confident with programatically changing Views, I have following problem:

在我的应用程序的第一个开始,我希望有一个覆盖主画面,告诉用户有一个看的设置,有两个重要的选项,用户必须配置。

At the first start of my app, I want to have an overlay for the main screen, that tells the user to have a look at the settings, as there are two critical options the user has to configure.

我不希望使用 AlertDialog 键,而不是使用向导。所以,我决定采取类似的方法来GO短信,并在第一次启动创建覆盖。我创建的实体模型看起来是这样的:

I don't want to use an AlertDialog and rather not use a wizard. So, I decided to take an approach similar to Go SMS and create an overlay at the first start. The mockup I created looks like this:

普通菜单:

Normal menu:

首先开始:

First start:

因此​​,这些都是问题,我有:

So these are the problems I have:

  1. 就像我说的,我不希望使用截屏覆盖在第一次启动,因为这会占用太多空间,不会是语言和画面无关。
  2. 我会圆为PNG,但我不知道究竟是如何把它在图像
  3. 同样的问题以文字
  4. 在最后,我想提出一个半透明的白色上的应用程序。它不一定需要孔为图标,虽然这将是很好的。

如果你需要的布局源,你可以在引擎收录

In case you need the Layout Source, you can get it at pastebin

所以,我只需要在这里得到一个开始,如果是更好地使用LayoutInflater或ViewStub以及如何去实现它,因为我绝对没有与它的经验...

So, I just need to get a start here, if it is better to use LayoutInflater or ViewStub and how to realize it, as I have absolutely no experience with it...

谢谢!

/编辑:我上传了一个新的,更加周密安排布局

/edit: I uploaded a new, more well-arranged layout.

推荐答案

我也遇到了类似的问题,我的客户想要的应用程序,在整个屏幕已经成为更白的演练(因为他们说:透明) ,除了按钮由复盖语音泡被解释。
幸运的是,你的布局是几乎没有复杂的对视了一眼,我与:)

I have faced a similar problem, I client wanted a walkthrough of the application, where the entire screen had to become whiter (as they said: "transparent"), except for the button being explained by an overlay speech-bubble.
Fortunately for you, your layout is not nearly as complicated as the one I had to work with :)

现在,你可以得到的透明效果有两种方式,要么有一个白色背景,并呼吁所有的意见setAlpha()方法,或者你可以创建一个半透明的白色覆盖。
如果你去的叠加,你必须找到一种方式,通过叠加显示不透明的按钮。这能有点复杂。 如果你去的第一个选项,你可以setAlpha(1)在不透明的观点得到它展现出来。

Now, you can get the transparency-effect in two ways, either have a white background and call all the views setAlpha() methods, or you can create a half-transparent white overlay.
If you go with the overlay, you'll have to find a way to display the opaque buttons through the overlay. This can get a bit complicated. If you go with the first option, you can just setAlpha(1) on the opaque view to get it to show up.

在setAlpha()方法只能从API版本11+,所以如果你的目标的早期版本,你可能需要做一个稍微复杂点的方式。
在视图上pre-蜂窝设定的α示例:

The setAlpha() method is only available from api version 11+, so if you target an earlier version, you might have to do it in a slightly more complicated way.
Example of setting alpha on views pre-honeycomb:

布局的按钮(让他们不过你想要的,只是让他们相似,所以你可以通过它们循环):

Layout for your buttons (make them however you want, just make them similar so you can loop through them):

<LinearLayout 
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <ImageView 
        android:tag="image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/tile"/>
    <TextView 
        android:tag="text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#FF000000"
        android:text="button1"/>
</LinearLayout>

在你的程序中,当你想使按钮透明的:

In your program, when you are want to make the buttons transparent:

LinearLayout l = (LinearLayout) findViewById(R.id.button1);
((ImageView)l.findViewWithTag("image")).setAlpha(0x7F);
((TextView)l.findViewWithTag("text")).setTextColor(0x7F000000);



当你决定要如何创建透明效果,你将不得不决定如何显示的叠加文本/泡沫。你很可能希望把这个在您的整个布局顶部的独立层,以确保它不会影响你的新看法。
实现这一目标的一个方法是通过改变你的根布局元素到的FrameLayout,然后创建/显示在此。例如:



When you have decided on how you want to create the transparency effect, you will have to decide on how to display the overlay-text/bubble. You'll most likely want to put this in a separate layer on top of your entire layout, to make sure that it is not affected by your new view.
One way to achieve this is by changing your root layout element to a FrameLayout, and then creating/displaying in this. e.g:

<FrameLayout background="#FFFF"> <!-- white background, just in case -->
    <LinearLayout>
        <!-- the rest of your layout -->
    </LinearLayout>
    <LinearLayout visibility="gone"> <!-- this will be your overlay view -->
        <ImageView /> <!-- the arrow/ring -->
        <TextView /> <!-- the description -->
    </LinearLayout>
</FrameLayout>

在显示的介绍,您可以设置隐藏的叠加视图表项的位置的位置加以解释,更改文本,以适当的字符串/资源,并显示该视图。

When the introduction is displayed, you set the position of the hidden overlay-view to the position of the table item to be explained, change the text to an appropriate string/resource and display the view.

在介绍结束后,你重置所有按钮的Alpha值,并设置叠加,再次去的知名度。

When the introduction is over, you reset the alpha values of all buttons, and set the visibility of the overlay to gone again.

这篇关于如何使用LayoutInflater / ViewStub用于覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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