1、RelativeLayout中如何获取控件相对于屏幕的坐标?

用View.getLocationOnScreen()方法。

2、如何用代码给RelativeLayout中的控件添加布局属性?

用addRule()的方法。

textView = (TextView)findViewById(R.id.text_view);RelativeLayout.LayoutParams para = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);para.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);textView.setLayoutParams(para);

前提是textView的母布局是个RelativeLayout。

3、GridLayout和TableLayout的区别,有变化。

参见 http://blog.csdn.net/runninglion/article/details/10813929 

4、如何实现截图?

利用/**
* 若要截图,在getDrawingCache前必须要measure和layout
* */
int widthMeasure = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
int heightMeasure = widthMeasure;
parent.measure(widthMeasure, heightMeasure);
parent.layout(0, 0, widthMeasure, heightMeasure);

这是骗人的,根本截不了。正确如下:

private void getDrawBitmap(){View parent = this.getWindow().getDecorView();//getLayoutInflater().inflate(R.layout.activity_main, null);if(parent == null){return;}parent.setDrawingCacheEnabled(true);//parent.buildDrawingCache();/** * 若要截图,在getDrawingCache前必须要measure和layout * */int widthMeasure = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);int heightMeasure = widthMeasure;parent.measure(widthMeasure, heightMeasure);parent.layout(0, 0, widthMeasure, heightMeasure);Bitmap b = parent.getDrawingCache();saveBitmap(b,"/storage/sdcard0/Download", "ttt.jpg");}/** * @param b * @param path * @param name * 保存图片 */private void saveBitmap(Bitmap b, String path,String name){File file = new File(path);if (!file.exists()){file.mkdir();}try {FileOutputStream fos = new FileOutputStream(path + "/" + name);b.compress(CompressFormat.JPEG, 85, fos);fos.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}

参见: http://blog.csdn.net/developer_jiangqq/article/details/12164239 http://whithin.blog.51cto.com/690417/1159072

5、如何设置Activity或View的背景颜色为渐变色??

//设置Activity从上到下的渐变色GradientDrawable gradientDraw = new GradientDrawable(Orientation.TOP_BOTTOM,new int[]{Color.RED, Color.YELLOW});getWindow().setBackgroundDrawable(gradientDraw);

效果:


更多关于GradientDrawable的用法: http://blog.csdn.net/qq315297923/article/details/8539736 


6、android 的layout_weight的含义:

表示view的原布局宽度再加上剩余空间的程度的比重,所以当两个View的宽度设为wrap_content和match_parent时设同样的weight得效果刚好相反的原因。

参见:

http://www.xiaoyunduo.org/article/97/ 

http://blog.csdn.net/jincf2011/article/details/6598256  

http://yulongsheng.blog.51cto.com/3804293/1260876

更多相关文章

  1. 使用Dialog实现PopupWindow效果
  2. Android(安卓)GestureDetector滑动监听事件
  3. 灵活使用Android中ActionBar和ViewPager切换页面
  4. 2.2.1 LinearLayout(线性布局)
  5. Android弹出式窗口PopuWindow的使用
  6. 了解使用Android(安卓)ConstraintLayout
  7. 主题:ListView(带图片)显示用法案例
  8. Android(安卓)CheckBox 控件突然报错
  9. Android中的加载动画效果

随机推荐

  1. 传蜂窝版本号为Android(安卓)2.4 明年2月
  2. [置顶] Android多分辨率和多屏幕的布局适
  3. Android(安卓)计算器
  4. 10个 iOS 用户暂可以嘲笑 Android(安卓)
  5. Android(安卓)4.4以后设置状态栏颜色
  6. Android动态加载jar/dex
  7. Android之SurfaceView简介(三)
  8. 谁说Android的动画不廉价(五)之水波纹动画
  9. 深入探讨 Android(安卓)传感器
  10. Android(安卓)如何检索Android设备的唯一