Android 终于官方支持按百分比来设置控件的宽高了

dependencies {
    compile ‘com.android.support:percent:22.2.0‘
}

支持布局

PercentRelativeLayout

<android.support.percent.PercentRelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/top_left"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_alignParentTop="true"
        android:background="#ff44aacc"
        app:layout_heightPercent="20%"
        app:layout_widthPercent="70%" />

    <View
        android:id="@+id/top_right"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/top_left"
        android:background="#ffe40000"
        app:layout_heightPercent="20%"
        app:layout_widthPercent="30%" />

    <View
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_below="@+id/top_left"
        android:background="#ff00ff22"
        app:layout_heightPercent="80%" />
</android.support.percent.PercentRelativeLayout>
时间: 2024-08-01 11:53:03

Android 终于官方支持按百分比来设置控件的宽高了的相关文章

android PercentRelativeLayout 支持百分比来设置控件的宽高

Android 最终官方支持按百分比来设置控件的宽高了. 我们先来看看效果:       看一下布局: PercentRelativeLayout <android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

android——如何理解控件的宽高及layout_grivaty与grivaty的区别

关于Layout_width/height引发的宽高思考 方式一: 结果不符合预期. 运行结果: 方式二: 结果符合预期. 如下图: Android控件宽高的规则: Android下的控件默认没有宽高,是由父控件给其宽高的. 其中一般的view控件是由(ViewGroup控件:LinearLayout.RelativeLayout .TableLayout.FrameLayout .AbsoluteLayou )五大布局给其宽高的. 而像LinearLayout.RelativeLayout等这

Android 如何在Java代码中手动设置控件的marginleft

1.定义LayoutParams LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);//定义一个LayoutParams 2.在LayoutParams中设置marginLeft layoutParams.setMargins(20,0,0,0);//4个参数

Android在onCreate中获取控件的宽高

在某些需求下,我们需要在onCreate的时候就获取到控件的宽高,但是如果直接用view.getWidth()或view.getHeight()会得到0.这是因为在onCreate执行的时候,控件还没有被绘制出来. 利用下面的方法可以获得控件的宽高: ViewTreeObserver vto = zoomImageView.getViewTreeObserver(); vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(

Android中控件的宽高

1.在一个Relatitivelayout布局里用代码add一个独立的button布局,结果该button的宽高无效 则说明:Android中控件默认是没有宽高的,只有五大布局才能给其宽高,即在代码中要设置控件的宽高需要使用福控件的layoutparams 命名规则:layout_width 想通的:layout_gravity和gravity 2.直接在activity中setContentView里引用最外层为button的布局,则也有宽高 原因:android默认在最外层给添加了Frame

Android开发技巧——定制仿微信图片裁剪控件

拍照--裁剪,或者是选择图片--裁剪,是我们设置头像或上传图片时经常需要的一组操作.上篇讲了Camera的使用,这篇讲一下我对图片裁剪的实现. 背景 下面的需求都来自产品. 裁剪图片要像微信那样,拖动和放大的是图片,裁剪框不动. 裁剪框外的内容要有半透明黑色遮罩. 裁剪框下面要显示一行提示文字(这点我至今还是持保留意见的). 在Android中,裁剪图片的控件库还是挺多的,特别是github上比较流行的几个,都已经进化到比较稳定的阶段,但比较遗憾的是它们的裁剪过程是拖动或缩放裁剪框,于是只好自己

Android自定义View(三、深入解析控件测量onMeasure)

转载请标明出处: http://blog.csdn.net/xmxkf/article/details/51490283 本文出自:[openXu的博客] 目录: onMeasure什么时候会被调用 onMeasure方法执行流程 MeasureSpec类 从ViewGroup的onMeasure到View的onMeasure ViewGroup中三个测量子控件的方法 getChildMeasureSpec方法 View的onMeasure setMeasuredDimension ??在上一篇

【转】获取Android控件的宽和高

我们都知道在onCreate()里面获取控件的高度是0,这是为什么呢?我们来看一下示例: 首先我们自己写一个控件,这个控件非常简单: public class MyImageView extends ImageView { public MyImageView(Context context, AttributeSet attrs) { super(context, attrs); } public MyImageView(Context context) { super(context); }

android在代码中四种设置控件背景颜色的方法(包括RGB)

转载请注明出处: http://blog.csdn.net/fth826595345/article/details/9208771  TextView tText=(TextView) findViewById(R.id.textv_name); //第1种: tText.setTextColor(android.graphics.Color.RED);//系统自带的颜色类 // 第2种: tText.setTextColor(0xffff00ff);//0xffff00ff是int类型的数据