首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >下移线性布局

下移线性布局
EN

Stack Overflow用户
提问于 2014-02-08 02:22:39
回答 3查看 6.3K关注 0票数 1

我在一个应用程序上工作,在一个xml文件中有2个线性布局。在开始时,一个线性布局被设置为不可见。当用户按下按钮时,可见的线性布局应该向下滑动90%,并显示第二个线性布局。我写了动画文件,并让它正常工作。我的问题是,在动画之后,视图又回到了原来的样子。如何将第一个线性布局向下移动以显示第二个线性布局?有什么帮助吗?

MainActivity文件:

代码语言:javascript
运行
复制
    public class MainActivity extends Activity implements   OnClickListener,AnimationListener{

LinearLayout main,menu;
    Button B;
    Animation slideUp;
    LinearLayout.LayoutParams params;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
       slideUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.main_slide_down);
    main=(LinearLayout)findViewById(R.id.maincontent);
    menu=(LinearLayout)findViewById(R.id.mainmenu);
    B= (Button)findViewById(R.id.button1);
    B.setOnClickListener(this);



    main.setLayoutAnimationListener(this);




}



@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId())
    {
       case R.id.button1:
        // main.setAnimation(slideUp);
        menu.setVisibility(View.VISIBLE);
        main.startAnimation(slideUp);


        break;

    }

}

}

XML文件:

代码语言:javascript
运行
复制
     <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"

tools:context=".MainActivity" >


<LinearLayout 
    android:layout_height="match_parent"
     android:layout_width="match_parent"
     android:id="@+id/mainmenu"
     android:background="#6F26F0"
     android:visibility="invisible" 
     android:orientation="vertical"
    >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

 </LinearLayout>


  <LinearLayout 
       android:layout_height="match_parent"
     android:layout_width="match_parent"
     android:id="@+id/maincontent"
      android:background="#3BED00"
         android:orientation="vertical"
    >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />



   </LinearLayout>





  </RelativeLayout>
EN

回答 3

Stack Overflow用户

发布于 2014-02-08 03:28:31

让我们丢弃动画,使用布局技巧!

这是你需要做的:

xml

·将根布局更改为LinearLayout

·将android:animateLayoutChanges="true"添加到根目录、主菜单和主内容

Android:id=“@+id/主菜单”

·将可见性更改为android:visibility="gone"

·将height更改为android:layout_height="0dp"

·增加android:layout_weight="1"的权重

Android:id=“@+id/主要内容”

·将height更改为android:layout_height="wrap_content"

现在怎么办?

你的任务完成了!只需将主菜单的可见性更改为单击按钮即可见!

票数 1
EN

Stack Overflow用户

发布于 2014-02-08 03:18:09

如何将第一个线性布局向下移动以显示第二个线性布局?

这就是你要做的:

代码语言:javascript
运行
复制
            main.startAnimation(slideUp);
            slideUp.setFillAfter(true);
            slideUp.setAnimationListener(new AnimationListener()
            {

                @Override
                public void onAnimationStart(Animation animation) {}

                @Override
                public void onAnimationRepeat(Animation animation) {}

                @Override
                public void onAnimationEnd(Animation animation) {

               // Make Your 1st Linearlayout Invisible/Gone &
               // Make your 2nd Linearlayout Visible here.

                }
            });
票数 0
EN

Stack Overflow用户

发布于 2015-12-13 02:28:19

您可能必须正确设置布局权重属性,才能使其占用90%的空间(0.9布局权重)。可见性可以在可见和消失之间切换。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21635050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档