2017-02-04 15 views
-1

我想执行布局的上移。幻灯片应从底部显示,其中包含一些文字。 以下是代码。构建时没有错误,但布局不能向上滑动。 活动调用扩展AppCompatActivity。无法在RelativeLayout上执行滑动动画

slide_up.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:fromYDelta="75%p" 
     android:toYDelta="100%p" 
     android:fillAfter="true" 
     android:duration="500" /> 
</set> 

布局文件:

<LinearLayout> 
    <RelativeLayout 
     android:id="@+id/time" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     android:visibility="gone" /> 
</LinearLayout> 

Activity.java

Animation bottomUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up); 
ViewGroup hiddenPanel = (ViewGroup)findViewById(R.id.time); 
hiddenPanel.startAnimation(bottomUp); 
hiddenPanel.setVisibility(View.VISIBLE); 

回答

0

尝试这是您的slid_up动画文件

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 

<translate 
    android:duration="1000" 
    android:fromYDelta="100%" 
    android:toYDelta="0" /> 
</set> 
+0

这不起作用。你能提出一些其他解决方案吗?我想布局在底部与顶部100dp的高度。 – Nikhil

+0

再次运气。我上面的代码中有任何错误?我应该将RelativeLayout更改为其他内容吗? – Nikhil

+0

LinearLayout还可以添加 –

0

试试这个:

为bottomup.xml:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate android:fromYDelta="75%p" android:toYDelta="0%p" 
    android:fillAfter="true" 
android:duration="500"/> 
</set> 

现在为您的布局:

<RelativeLayout 
    android:id="@+id/hidden_panel" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" 
    android:visibility="gone" > 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/app_name" 
     android:layout_centerInParent="true" 
     android:onClick="slideUpDown" /> 
</RelativeLayout> 

在代码中添加onClick方法

public void slideUpDown(final View view) { 
    if (!isPanelShown()) { 
     // Show the panel 
     Animation bottomUp = AnimationUtils.loadAnimation(this, 
       R.anim.bottom_up); 

     hiddenPanel.startAnimation(bottomUp); 
     hiddenPanel.setVisibility(View.VISIBLE); 
    } 
} 

private boolean isPanelShown() { 
    return hiddenPanel.getVisibility() == View.VISIBLE; 
} 

其中hiddenPanel = findViewById(R.id.hidden_panel);

+0

这不行的 – Nikhil

+0

尝试添加不同的背景色.. – rafsanahmad007