<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmls:android="http://schema.android.com/apk/res/android" -----------------------*
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<LinearLayout
android:id="@+id/menu"
android:layout_width="fill_parent"
android:layout_height="100px"
android:layout_alignParentTop="true"
android:background="#ffffff">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="I'm a menu"
android:gravity="center"/>
</LinearLayout>
<Button
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Click to show/hiden menu"/>
</RelativeLayout>
*处error: Error parsing XML: unbound prefix应该怎么改?求助
改成
<RelativeLayout xmlns:android="http://schema.android.com/apk/res/android"
改成
<RelativeLayout xmlns:android="http://schema.android.com/apk/res/android"哈哈哈,LZ细心点哦!一个字母的问题!
package ydream.wei;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.LinearLayout;public class TranslateAnimationMenu extends Activity {
/** Called when the activity is first created. */
private Animation showAction,hideAction = null;
private LinearLayout menu = null;
private Button btn = null;
private boolean menushowed;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
menu = (LinearLayout)findViewById(R.id.menu);
btn = (Button)findViewById(R.id.btn);
//TranslateAnimation动画
showAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
//ScaleAnimation动画
//showAction = new ScaleAnimation(1.0f,1.0f,0.0f,1.0f,Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,0.0f);
showAction.setDuration(500);
//TranslateAnimation动画
hideAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f);
//ScaleAnimation动画
//hideAction = new ScaleAnimation(1.0f,1.0f,1.0f,0.0f,Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,0.0f);
hideAction.setDuration(500);
menushowed = false;
menu.setVisibility(View.GONE);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(menushowed){
menushowed = false;
menu.startAnimation(hideAction);
menu.setVisibility(View.GONE);
}
else{
menushowed = true;
menu.startAnimation(showAction);
menu.setVisibility(View.VISIBLE);
}
}
});
}
}
布局文件是上面那个,但程序不能运行啊。
07-25 07:31:33.431: ERROR/AndroidRuntime(328): java.lang.RuntimeException: Unable to start activity ComponentInfo{ydream.wei/ydream.wei.TranslateAnimationMenu}: java.lang.RuntimeException: Binary XML file line #3: You must supply a layout_width attribute.
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.os.Looper.loop(Looper.java:123)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at java.lang.reflect.Method.invoke(Method.java:521)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at dalvik.system.NativeStart.main(Native Method)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): Caused by: java.lang.RuntimeException: Binary XML file line #3: You must supply a layout_width attribute.
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:3592)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:3672)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:452)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:418)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:48)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.app.Activity.setContentView(Activity.java:1647)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at ydream.wei.TranslateAnimationMenu.onCreate(TranslateAnimationMenu.java:22)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-25 07:31:33.431: ERROR/AndroidRuntime(328): ... 11 more
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<LinearLayout
android:id="@+id/menu"
android:layout_width="fill_parent"
android:layout_height="100px"
android:layout_alignParentTop="true"
android:background="#ffffff">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="I'm a menu"
android:gravity="center"/>
</LinearLayout>
<Button
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Click to show/hiden menu"/>
</RelativeLayout>
07-25 07:31:33.431: ERROR/AndroidRuntime(328): java.lang.RuntimeException: Unable to start activity ComponentInfo{ydream.wei/ydream.wei.TranslateAnimationMenu}: java.lang.RuntimeException: Binary XML file line #3: You must supply a layout_width attribute.建议楼主用以下布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/download_manager_layout">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
<LinearLayout android:id="@+id/menu" android:layout_width="fill_parent"
android:layout_height="100px" android:layout_alignParentTop="true"
android:background="#ffffff">
<TextView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="I'm a menu"
android:gravity="center" />
</LinearLayout>
<Button android:id="@+id/btn" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:text="Click to show/hiden menu" />
</RelativeLayout>
跟你的布局一模一样的。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"