Android 使用代码去调整左右margin
RelativeLayout.LayoutParams leftParams = (RelativeLayout.LayoutParams) arrow_left.getLayoutParams(); leftParams.rightMargin = -getResources().getDimensionPixelSize(R.dimen.dp10); rightParams.leftMargin = -getResources().getDimensionPixelSize(R.dimen.dp10); arrow_left.setLayoutParams(leftParams);
Android 使用代码去调整图片宽度
RelativeLayout.LayoutParams imagesParams = (RelativeLayout.LayoutParams) im_UserImage.getLayoutParams(); imagesParams.width = getResources().getDimensionPixelOffset(R.dimen.dp35); imagesParams.height = getResources().getDimensionPixelOffset(R.dimen.dp35); im_UserImage.setLayoutParams(imagesParams);
Android 使用代码给文字设置颜色
card_title_name.setTextColor(getResources().getColor(R.color.black));
Android 代码获取屏幕宽高
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); int width = wm.getDefaultDisplay().getWidth(); int height = wm.getDefaultDisplay().getHeight();
Android 使用LayoutInflater加载布局
LayoutInflater技术广泛应用于需要动态添加View
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.share_item, this);
Android 四种加载模式
Standard 默认模式 SingleTop SingleTask SingleInstance
在AndroidManifest.xml中通过给<activity>标签指定android:lauchMode属性来选择启动模式
Android 添加Fragment
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); oneFragment fragment_one = new oneFragment(); fragmentTransaction.replace(R.id.f_one, fragment_one); fragmentTransaction.commitAllowingStateLoss();
Android TextView 文字过长且内容自动换行问题处理
android:ellipsize = "end" 省略号在结尾 android:ellipsize = "start" 省略号在开头 android:ellipsize = "middle" 省略号在中间 android:ellipsize = "marquee" 跑马灯 android:singleline = "true" 文字不会自动换行
EditText 属性
android:background="@null"//edittext 去边框 android:hint="请输入数字!"//设置显示在控件上的提示信息 android:numeric="integer"//设置只能输入整数,如果是小数则是:decimal android:singleLine="true"//设置单行输入,一旦设置为true,则文字不会自动换行。 android:password="true"//设置只能输入密码 android:textStyle="bold"//字体,bold粗体, italic斜体, bolditalic斜粗体
AndroidManifest.xml 以下两种配置缺一不可
<action name="android.intent.action.Main"/> 决定应用程序最先启动的Activity 如没有设置,则不知启动哪个Activity, 图标也将不会出现 <category name="android.intent.category.LAUNCHER"/> 决定应用程序是否显示在程序列表里 如没有声明此项,则eclipse运行报错,且应用图标在桌面上无法显示
ListView添加头部 addHeaderView(view) LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); LinearLayout headerLayout = (LinearLayout) inflater.inflate(R.layout.all_topic_picker_tab_layout, null); mItemList.addHeaderView(headerLayout); mItemList.setAdapter(mAdapter);(addHeaderView放入setAdapter前)