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
错误提示: java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.TextView...出现原因: xml中更改布局,替换了父viewGroup,比如说从当前LinearLayout移动到另一个RelativeLayout 解决办法: 检查一下之前有没有使用LayoutParams...,如果有,将【原来ViewGroup】.LayoutParams改成【新viewGraoup】.LayoutParams 如果没有使用LayoutParams,移动xml布局后报这个错,可能是之前编译生成的
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
import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.LinearLayout...MatchParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT...( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); //设置TextView的参数 LinearLayout.LayoutParams...TextViewParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT...android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.LinearLayout
import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.widget.LinearLayout...; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout...getParams(WindowManager.LayoutParams wmParams) { if (wmParams == null) { wmParams = new WindowManager.LayoutParams...//wmParams.type = LayoutParams.TYPE_SYSTEM_ALERT; wmParams.type = LayoutParams.TYPE_SYSTEM_ERROR; /...| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
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
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
而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
android.support.v4.view.ViewPager; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout.../** * 添加ImageView */ mImageList = new ArrayList< (); //额外添加两张图片 ViewGroup.LayoutParams...layoutParams = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT,...ViewGroup.LayoutParams.WRAP_CONTENT); for (int i = 0; i < mImageIds.length; i++) {...ImageView imageView = new ImageView(mContext); imageView.setLayoutParams(layoutParams); mImageList.add
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.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
import android.view.accessibility.AccessibilityNodeInfo; import android.widget.CompoundButton; import android.widget.LinearLayout...p instanceof RadioGroup.LayoutParams; } @Override protected LinearLayout.LayoutParams generateDefaultLayoutParams...() { return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); } @Override public...extends LinearLayout.LayoutParams { /** * {@inheritDoc} */ public LayoutParams(Context c, AttributeSet...); } /** * {@inheritDoc} */ public LayoutParams(ViewGroup.LayoutParams p) { super(p); } /** * {@inheritDoc
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.os.Handler; import android.view.Gravity; import android.view.View; import android.view.WindowManager; import android.widget.LinearLayout...mParams = new WindowManager.LayoutParams(); public CToast(Context context) { init(context); } /** *...params = mParams; params.height = WindowManager.LayoutParams.WRAP_CONTENT; params.width = WindowManager.LayoutParams.WRAP_CONTENT...; params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE...= android.R.style.Animation_Toast; params.type = WindowManager.LayoutParams.TYPE_TOAST; params.setTitle
android.view.ViewGroup; import android.widget.AbsListView; import android.widget.BaseAdapter; import android.widget.LinearLayout...); ListView listView; LinearLayout loadingLayout; private Thread mThread; /** * 设置布局显示属性 */ private LayoutParams...mLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT...); /** * 设置布局显示目标最大化属性 */ private LayoutParams FFlayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT..., LinearLayout.LayoutParams.FILL_PARENT); private ProgressBar progressBar; /** Called when the activity
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.<em>LayoutParams</em>... lParams = new LinearLayout.<em>LayoutParams</em>(<em>LayoutParams</em>.MATCH_PARENT, getStatusBarHeight());
; 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.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.LinearLayout...lp = new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); //LayoutInflater...lp = new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout...vlp = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT...); ViewGroup.LayoutParams vlp2 = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.View; import android.view.ViewConfiguration; import android.view.WindowManager; import android.widget.LinearLayout...params = new LayoutParams(); params.x = screenWidth/2; params.y = screenHeight/2+150; params.width =...LayoutParams.WRAP_CONTENT; params.height = LayoutParams.WRAP_CONTENT; params.gravity = Gravity.LEFT...| Gravity.TOP; params.type = LayoutParams.TYPE_APPLICATION_OVERLAY; params.format = PixelFormat.RGBA_...8888; params.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_NOT_FOCUSABLE; mBallView.setLayoutParams
; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams...; import android.widget.ImageView; import android.widget.LinearLayout; public class Activity01 extends...,R.drawable.guide2,R.drawable.guide3,R.drawable.guide4}; views=new ArrayList<View (); //给iamgeView设置LayoutParams...参数 LayoutParams layoutParams=new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);...1 ImageView imageView=new ImageView(this); imageView.setImageResource(i); imageView.setLayoutParams(layoutParams
领取专属 10元无门槛券
手把手带您无忧上云