今天给大家带来的是自定义View,然后如何设置他的宽高,经常用自定义view的程序猿肯定都知道我们在给自定义view设置wrap_content或者match_parent,view都会占满全屏,就想如下
以下是方法,不提供自定义view的布局了,很简单,就是绘一个蓝色的圆
第一种方式(布局修改)
第一种方法也是最简单的方法,我们直接给自定义view限制一个宽高
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.administrator.ceshi.MainActivity">
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@color/colorAccent"/>
效果如下