0

我有我的类扩展了baseActivity,除了文本视图上的一个简单的onClick之外,一切都很好:-|

TextView labelName_view = (TextView) findViewById(R.id.labelName);
labelName_view.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        // animazione automatica al click
        LinearLayout contenitore_cibo_l=(LinearLayout) findViewById(R.id.bottom_container);
        LayoutParams lp = (LayoutParams) contenitore_cibo_l.getLayoutParams();
        System.out.println(lp.topMargin);
        //contenitore_cibo_l.startAnimation(makeAnimation_ordini(400, 25));
    }
});

当我点击时,它会崩溃:

05-27 12:30:22.722: E/AndroidRuntime(2932): FATAL EXCEPTION: main
05-27 12:30:22.722: E/AndroidRuntime(2932): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.app.ActionBar$LayoutParams
05-27 12:30:22.722: E/AndroidRuntime(2932):     at com.web_pos.android.OrderActivity$4.onClick(OrderActivity.java:296)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at android.view.View.performClick(View.java:3511)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at android.view.View$PerformClick.run(View.java:14105)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at android.os.Handler.handleCallback(Handler.java:605)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at android.os.Looper.loop(Looper.java:137)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at android.app.ActivityThread.main(ActivityThread.java:4424)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at java.lang.reflect.Method.invokeNative(Native Method)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at java.lang.reflect.Method.invoke(Method.java:511)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-27 12:30:22.722: E/AndroidRuntime(2932):     at dalvik.system.NativeStart.main(Native Method)
4

3 回答 3

2

问题在于LayoutParams您使用的类型。从日志看来,您正在使用android.app.ActionBar.LayoutParams. 将其更改为android.widget.RelativeLayout.LayoutParams,它应该可以顺利运行。希望能帮助到你。

于 2013-05-27T12:34:40.147 回答
1

您必须始终采用要更改布局的容器布局的布局参数,假设我想更改线性布局中的按钮布局,因此我必须采用线性布局参数

于 2013-05-27T12:37:00.347 回答
0

您需要更正 LayoutParams 的导入语句。

而不是导入 android.app.ActionBar.LayoutParams,你应该导入 android.widget.RelativeLayout.LayoutParams

于 2013-05-27T12:35:12.807 回答