【发布时间】:2017-07-21 07:54:23
【问题描述】:
我正在尝试创建一个下拉动画。当用户点击指定按钮@+id/btnToHideView 时,我希望视图@+id/relativeLayoutControls 下拉/向上滑动(VISIBLE / GONE)。
这是布局文件的外观:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnToHideView"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/hide_btn"
/>
<RelativeLayout
android:id="@+id/relativeLayoutControls"
android:layout_width="60dp"
android:layout_height="fill_parent"
android:layout_marginRight="6dp"
android:layout_marginEnd="6dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
//I have buttons in this layoout
</RelativeLayout>
</LinearLayout>
这是我尝试过的:
我在res/anim创建了2个动画文件
slide_down.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="1000"
android:fromYDelta="0"
android:toYDelta="100%" />
</set>
slide_up.xml
<?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>
然后我尝试这样做:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
controlsHide = (RelativeLayout) findViewById(R.id.relativeLayoutControls);
final Animation slide_down = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.slide_down);
final Animation slide_up = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.slide_up);
btnToHideView = (Button) findViewById(R.id.btnToHideView);
btnToHideView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//I just did slide_up to test if its working
controlsHide.startAnimation(slide_up);
}
});
我关注了this post,但是当我点击按钮时没有任何反应。在 logcat 中,它只打印ACTION_DOWN。
【问题讨论】:
标签: android animation drop-down-menu