移动线性布局下降 [英] moving linear layout down
问题描述
IM上的应用程序工作在一个XML文件中2线性布局。在启动一个线性布局设置为不可见。当用户按下一个按钮,可见线性布局应滑下90%的方式,并显示所述第二的LinearLayout。我写的动画文件,并将它做工精细。我的问题是动画后认为可以追溯到是怎么回事。如何移动第一线性布局下,显示第二线性布局?任何帮助吗?
MainActivity文件:
公共类MainActivity扩展活动实现OnClickListener,AnimationListener {主要的LinearLayout,菜单;
按钮B;
动画效果基本show;
LinearLayout.LayoutParams PARAMS;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
效果基本show = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.main_slide_down);
主要=(的LinearLayout)findViewById(R.id.maincontent);
菜单=(的LinearLayout)findViewById(R.id.mainmenu);
B =(按钮)findViewById(R.id.button1);
B.setOnClickListener(本); main.setLayoutAnimationListener(本);
}@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
开关(v.getId())
{
案例R.id.button1:
// main.setAnimation(效果基本show);
menu.setVisibility(View.VISIBLE);
main.startAnimation(效果基本show);
打破; }}
}
XML文件:
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent工具:上下文=MainActivity。>
<的LinearLayout
机器人:layout_height =match_parent
机器人:layout_width =match_parent
机器人:ID =@ + ID / MainMenu的
机器人:背景=#6F26F0
机器人:知名度=隐形
机器人:方向=垂直
>
< ImageView的
机器人:ID =@ + ID / imageView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/ ic_launcher/> < / LinearLayout中>
<的LinearLayout
机器人:layout_height =match_parent
机器人:layout_width =match_parent
机器人:ID =@ + ID /日程地址搜索Maincontent
机器人:背景=#3BED00
机器人:方向=垂直
> <按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=按钮/> < / LinearLayout中> < / RelativeLayout的>
让废钢动画和使用布局招,而不是!
这里就是你需要做的:
的 XML 的
•更改根布局为的LinearLayout
•添加的android:animateLayoutChanges =真正的
来根的MainMenu和放大器;日程地址搜索Maincontent
的机器人:ID =@ + ID / MainMenu的的
•更改能见度安卓知名度=水涨船高
•更改高度的android:layout_height =0dp
•添加重量的android:layout_weight =1
的机器人:ID =@ + ID /日程地址搜索Maincontent的
•更改高度的android:layout_height =WRAP_CONTENT
现在怎么办?
您就大功告成了!刚刚的MainMenu的可见性改为显示您点击按钮!
im working on a app the has 2 linear Layouts in one xml file. on start one linear-layout is set to invisible. When the user pushes a button the visible linear-layout should slide down 90% of the way and show the second linearlayout. I wrote the animation file and have it working fine. My problem is that after the animation the view goes back to how it was. How do i move the first linear layout down to show the second linear layout? Any help?
MainActivity file:
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 file:
<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>
Let's scrap the animations and use a layout trick instead!
Here's what you need to do:
xml
• Change root layout to LinearLayout
• Add android:animateLayoutChanges="true"
to root, mainmenu & maincontent
android:id="@+id/mainmenu"
• Change visibility to android:visibility="gone"
• Change height to android:layout_height="0dp"
• Add weight of android:layout_weight="1"
android:id="@+id/maincontent"
• Change height to android:layout_height="wrap_content"
Now what?
You're done! Just change the visiblity of mainmenu to visible on the click of your button!
这篇关于移动线性布局下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!