如何显示在其他编程的顶部在我的情况下,一个布局? [英] How to show one layout on top of the other programmatically in my case?

查看:85
本文介绍了如何显示在其他编程的顶部在我的情况下,一个布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主要布局的的main.xml 简单地包含了两个LinearLayouts:

My main layout main.xml simply contains two LinearLayouts:

  • 第1 的LinearLayout 举办 VideoView 按钮
  • 第二届的LinearLayout 承载了的EditText ,而这个的LinearLayout 已设定的能见度 GONE 安卓知名度=水涨船高
  • The 1st LinearLayout hosts a VideoView and a Button,
  • The 2nd LinearLayout hosts an EditText, and this LinearLayout has set the visibility value to "GONE" (android:visibility="gone")

象下面这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
        android:orientation="vertical"
>
    <LinearLayout 
        android:id="@+id/first_ll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"

    >
        <VideoView 
            android:id="@+id/my_video"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="9"
        />

        <Button
            android:id="@+id/my_btn"
            android:layout_width="30dip" 
            android:layout_height="30dip"
            android:layout_gravity="right|bottom"
                android:layout_weight="1"
        />

    </LinearLayout>

    <LinearLayout 
        android:id="@+id/second_ll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="2dip"

        android:visibility="gone"
    >
        <EditText 
            android:id="@+id/edit_text_field"
            android:layout_height="40dip"
            android:layout_width="fill_parent"
            android:layout_weight="5"
            android:layout_gravity="center_vertical"
        />

    </LinearLayout>
</LinearLayout>

我成功地实现了功能,当按钮(id为my_btn的)是pressed,在第二 的LinearLayout 的EditText 字段显示,与下面的Java code:

I successfully implemented the feature that when the Button (with id my_btn) is pressed, the 2nd LinearLayout with EditText field is shown, with the following Java code:

LinearLayout secondLL = (LinearLayout) findViewById(R.id.second_ll);

Button myBtn = (Button) findViewById(R.id.my_btn);
myBtn.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v){
        int visibility = secondLL.getVisibility();

        if(visibility==View.GONE)
            secondLL.setVisibility(View.VISIBLE);

    }
}); 

通过上面的Java code,在第二 的LinearLayout 的EditText 如图例如低于追加第1 的LinearLayout 这是有道理的。

With the above Java code, the 2nd LinearLayout with EditText is shown like appending below the 1st LinearLayout which makes sense.

,我需要的是:当按钮(ID:my_btn的)是pressed,在第二 的LinearLayout 的EditText 显示在第一顶 的LinearLayout ,它看起来像在第二 的LinearLayout 的EditText 从屏幕底部的上升,并在第二 的LinearLayout 的EditText 仅占从屏幕底部的一部分,这是第一次的LinearLayout仍清晰可见,就像下面的图片显示:

BUT, What I need is: when Button(id: my_btn) is pressed, the 2nd LinearLayout with EditText is shown on top of the 1st LinearLayout, which looks like the 2nd LinearLayout with EditText is rising from the bottom of screen, and the 2nd LinearLayout with EditText only occupy part of the screen from bottom, that's the 1st LinearLayout still visible, like the image below showed:

所以,当按钮(ID:my_btn的)是pressed如何显示在第二 的LinearLayout 的EditText 第一顶 的LinearLayout ,而不是附加的第二 的LinearLayout 下面的第1 的LinearLayout 编程?

So, when Button(id: my_btn) is pressed how to show the 2nd LinearLayout with EditText on top of the 1st LinearLayout instead of appending 2nd LinearLayout below 1st LinearLayout programmatically?

推荐答案

使用的FrameLayout有两个孩子。这两个孩子会重叠。这是建议在从机器人实际上是一个教程,它不是一个黑客...

Use a FrameLayout with two children. The two children will be overlapped. This is recommended in one of the tutorials from Android actually, it's not a hack...

这里是一个TextView显示在一个ImageView的上面的例子:

Here is an example where a TextView is displayed on top of an ImageView:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <ImageView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

    android:scaleType="center"
    android:src="@drawable/golden_gate" />

  <TextView
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="20dip"
    android:layout_gravity="center_horizontal|bottom"

    android:padding="12dip"

    android:background="#AA000000"
    android:textColor="#ffffffff"

    android:text="Golden Gate" />

</FrameLayout>

这篇关于如何显示在其他编程的顶部在我的情况下,一个布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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