2017-02-04 28 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