我想在Android中创建一个Reveal菜单,就像Jquery mobile一样。 我希望主FrameLayout向左滑动30%,然后显示其后面的另一个布局,即菜单布局。
滑动FrameLayout的编码成功;那是当我点击菜单时,它左侧30%的距离。 我遇到的问题是,当它向左滑动时,菜单按钮在其当前位置停止响应,但它在其初始位置响应,而菜单按钮已向下移动了framelayout 30%
这是我的代码
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:id="@+id/act_menu"
android:layout_width="200dp"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.thankgod.slidemenu.MainActivity">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu"
android:layout_height="match_parent"
android:layout_width="200dp"
android:background="@color/colorPrimaryDark"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</FrameLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/act_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.thankgod.slidemenu.MainActivity">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Dark">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimaryDark">
<Button
android:text="@string/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button" />
<Button
android:text="@string/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
tools:ignore="RelativeOverlap" />
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
</RelativeLayout>
MainActivity.java
package com.example.thankgod.slidemenu;
import android.app.Activity;
import android.support.annotation.Nullable;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.FrameLayout;
public class MainActivity extends Activity {
int page = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);*/
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
move();
}
});
}
public void move() {
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.act_main);
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide);
frameLayout.startAnimation(anim);
}
}
动画文件slide.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%"
android:toXDelta="20%"
android:duration="300"/>
</set>
答案 0 :(得分:0)
再次单击菜单按钮,它再次调用移动方法,但它不能再移动30%,所以看起来没有移动使用下面的代码。
>>> a=u'-100'
>>> int(a)
-100
>>> float(a)
-100.0