1 问题: 在Android Activity中,用java代码进行LayoutParams参数设置的时候,出现如下错误: java.lang.ClassCastException: android.widget.FrameLayoutLayoutParams...LayoutParams使用规则:“父Layout”为子控件分配空间的时候,获取”子Layout”的LayoutParams的必须是“父Layout”.LayoutParams,而非子Layout的LayoutParams...如果要在代码里设置B的LayoutParams,B的LayoutParams要为RelativeLayout.LayoutParams。...分析:“要在代码里设置B的LayoutParams”,就要用B的父Layout的LayoutParams,即RelativeLayout A得LayoutParams, 代码如下: RelativeLayout.LayoutParams...params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT
kankan.wheel.widget.WheelView; import android.content.Context; import android.util.AttributeSet; import android.widget.LinearLayout...newDays_param = new LayoutParams(300,LayoutParams.WRAP_CONTENT); newDays_param.setMargins(0,...kankan.wheel.widget.WheelView; import android.content.Context; import android.util.AttributeSet; import android.widget.LinearLayout...lparams_hours = new LayoutParams(80,LayoutParams.WRAP_CONTENT); lparams_hours.setMargins(0,...import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout
android.view.MotionEvent; import android.view.View; import android.view.animation.AnimationUtils; import android.widget.LinearLayout...TextView(this); textView.setTextSize(100); textView.setLayoutParams(new TextSwitcher.LayoutParams...( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.LinearLayout...import android.view.Window; import android.widget.Button; import android.widget.FrameLayout; import android.widget.LinearLayout...android.view.GestureDetector.OnGestureListener; import android.widget.Button; import android.widget.FrameLayout; import android.widget.LinearLayout...对象用于指定控件的大小和在父容器中的相对位置 final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams...( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.gravity
错误提示: java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.TextView...出现原因: xml中更改布局,替换了父viewGroup,比如说从当前LinearLayout移动到另一个RelativeLayout 解决办法: 检查一下之前有没有使用LayoutParams...,如果有,将【原来ViewGroup】.LayoutParams改成【新viewGraoup】.LayoutParams 如果没有使用LayoutParams,移动xml布局后报这个错,可能是之前编译生成的
import android.view.View.OnClickListener; import android.view.Window; import android.view.WindowManager.LayoutParams...; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.LinearLayout...initNightView() { if (mIsAddedView == true) return; myNightViewParams = new LayoutParams...(LayoutParams.TYPE_APPLICATION, LayoutParams.FLAG_NOT_TOUCHABLE ...| LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSPARENT); manager = (WindowManager
FrameLayout的父控件是一个LinearLayout控件,问题出在,LinearLayout为子控件分配空间的时候,获取FrameLayout的LayoutParams的必须为LinearLayout.LayoutParams...,而非FrameLayout.LayoutParams。...如果要在代码里设置B的LayoutParams,B的LayoutParams要为RelativeLayout.LayoutParams。...RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT...,它的外层不是RelativeLayout了,导致笔者的代码一直报错 java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams
AndroidRuntime(12237): Process: com.example.nongmin, PID: 12237 09-24 13:19:06.850: E/AndroidRuntime(12237): java.lang.ClassCastException...: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
android.view.ViewTreeObserver import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout...= LinearLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.MATCH_PARENT...= LinearLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.MATCH_PARENT...= FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT...:ViewGroup.LayoutParams = this@ContextTitle.layoutParams layoutparams.height = layoutparams.height
而LayoutParams呢?是时候在这里做个了断了。 LayoutParams是什么? LayoutParams,顾名思义,就是Layout Parameters :布局参数。...– 基类LayoutParams(也就是ViewGroup.LayoutParams)仅仅描述了这个View想要的宽度和高度。...(new ViewGroup.LayoutParams(100,100)); 会直接报ClassCastException: java.lang.ClassCastException: android.view.ViewGroup...$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams 上面这种异常熟悉么?...== VERTICAL) { return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT
; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup.LayoutParams...( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); return iv; } } @SuppressLint(...否则会报错“java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.Gallery...$LayoutParams” card.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT...new ImageView(mContext); iv.setImageResource(mImageRes[position]); iv.setLayoutParams(new Gallery.LayoutParams
android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.LinearLayout..., WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION..., WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } <span style="white-space:pre...// 创建TextView TextView textView = new TextView(this); LinearLayout.LayoutParams... lParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, getStatusBarHeight());
android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout...layoutparams1 = new LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);...leftTextparams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)...titleTextparams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER...rightTextParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT
android.graphics.Color; import android.os.Bundle; import android.view.Gravity; import android.view.ViewGroup; import android.widget.LinearLayout...textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT..., LinearLayout.LayoutParams.WRAP_CONTENT)); // 设置TextView的文字 textView.setText
android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout...LayoutParams = (LinearLayout.LayoutParams) laySearch.getLayoutParams(); LayoutParams.width =...dip2px(px2dip(width)-40); LayoutParams.setMargins(dip2px(0), dip2px(0), dip2px(0), dip2px(0)...LayoutParams = (LinearLayout.LayoutParams) laySearch.getLayoutParams(); LayoutParams.width =...dip2px(48); LayoutParams.height = dip2px(48); LayoutParams.setMargins(dip2px(0), dip2px
import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.LinearLayout...( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT...); tw.setOrientation(TabWidget.HORIZONTAL); ll.addView(tw, new LinearLayout.LayoutParams...( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT...( LinearLayout.LayoutParams.MATCH_PARENT, 0, 1)); } } /** *
; import android.widget.ImageView; import android.widget.LinearLayout; public class TwoActivity extends...tips.length; i++){ ImageView imageView = new ImageView(this); imageView.setLayoutParams(new LayoutParams...layoutParams = new LinearLayout.LayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT,...LayoutParams.WRAP_CONTENT)); layoutParams.leftMargin = 5; layoutParams.rightMargin...= 5; group.addView(imageView, layoutParams); } //将图片装载到数组中 mImageViews = new ImageView
android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.LinearLayout...requestWindowFeature(Window.FEATURE_NO_TITLE); // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN..., // WindowManager.LayoutParams.FLAG_FULLSCREEN); LinearLayout
android.content.DialogInterface; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout...inflater.inflate(R.layout.dialog_normal_layout, null); dialog.addContentView(layout, new LinearLayout.LayoutParams...( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT))...) layout.findViewById(R.id.content)) .addView(contentView, new LinearLayout.LayoutParams...(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); }
; import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; import android.widget.LinearLayout...layoutParams = (LinearLayout.LayoutParams) getLayoutParams(); if (layoutParams == null)...{ layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT...; import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; import android.widget.LinearLayout...layoutParams = (LinearLayout.LayoutParams) getLayoutParams(); if (layoutParams == null)