在开发Android过程中,有时已有的Loyout布局不能完全满足设计需求,这时需要在已有的Layout基础上上进行扩展,以达到通过配置文件描述布局的设计原则。
首先第一一个布局类,重写其onDraw方法。
public static class iRelativeLayout extends RelativeLayout
{
private Paint mPaint;
private Rect mRect;
public iRelativeLayout( Context context, AttributeSet attrs ) {
super(context, attrs);
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setColor(0xFFCBD2D8);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawColor(0xFFC5CCD4);
this.getDrawingRect(mRect);
for (int i = 0; i < mRect.right; i += 7)
{
canvas.drawRect(mRect.left + i, mRect.top, mRect.left + i + 2,
mRect.bottom, mPaint);
}
}
}
其次,在布局配置文件中引用:
<?xml version="1.0" encoding="utf-8"?>
<view xmlns:android="http://schemas.android.com/apk/res/android"
class="iRelativeLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background = "#C5CCD4FF"
>
<LinearLayout
android:id = "@+id/TabLayout_One"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:layout_above = "@+id/Tabs"
>
<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
<RelativeLayout
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:visibility = "visible"
>
<Button
android:id = "@+id/ButtonOne"
android:layout_width = "wrap_content"
android:layout_height = "fill_parent"
android:text = "h3h3h3"
/>
<Button
android:id = "@+id/ButtonTwo"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "11222"
android:layout_below ="@+id/ButtonOne"
/>
<Button
android:id = "@+id/ButtonThree"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "wass"
android:layout_below ="@+id/ButtonTwo"
/>
</RelativeLayout>
</ScrollView>
</LinearLayout>
</view>
最后,和其他布局一样使用即可。
分享到:
相关推荐
android提供的五种布局有时候不能满足实际项目的需要,所以需要自定义布局。这是一个自定义Layout布局
自定义右上角带叉号的Dialog ,自定义布局的dialog,支持点击事件
NULL 博文链接:https://a-bin.iteye.com/blog/1183227
http://blog.csdn.net/qq970259858/article/details/51661407
<?xml version="1.0" encoding="UTF-8"?> ... android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" > ... android:layout_width="300...android自定义弹出框,很实用的
本文举例说明在Preference中自定义layout的方法。笔者是为了在设置中插入@有米v4广告条才研究了一晚上的。正文:首先PreferenceScreen是一个xml文件于res/xml目录下,不属于layout文件。要插入layout,有两种方法。 ...
CustomLayout Android 自定义ListView 与Dialog Layout 之范例。 (2015程设暑期加强班专用)
android:layout_width="match_parent" android:layout_height="200dip" android:background="@color/backColor"> </com.hao.percentlayout.layout.PercentLinearLayout> //相对布局 <com.hao.percentlayout....
自己写的简单的圆形布局layout,布局内部可以放各种控件,如Textview,ImageView,Edittext,Button 等等,希望对大家有用!
自定义layout 并拦截内部触发事件 实现sliding的效果
上篇博文代码实现了Android自带的preference组件,本文将通过实例讲解自定义preference组件。 主要通过以下几步来实现: 1.定义需要的layout布局res->layout->xml文件; 2.通过继承Preference类,来实现自定义...
android自定义viewgroup实现等分格子布局
Layout: <?xml version=1.0 encoding=utf-8?> <merge xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools> <RelativeLayout android:id=@+id/...
Android自定义View以及layout属性全攻略.txt
anroid中实现对上拉下滑实现布局的自定义,这个是建立在swiperefresh基础之上
android 自定义右上角为关闭按钮X的dialog,其中X是文字按钮。是在网站上不可用的基础上,用RelativeLayout 改的。
Custom shaped layout for Android 自定义形状布局 Features Clip layout and its childview. 2 way to set shape. Also custom shape by implement ShapeModel. Dependency Add this in your build.gradle file ...
SwagPoints SwagPoints - An Android custom circular SeekBar that supports ... android:layout_width="match_parent" android:layout_height="340dp" android:layout_gravity="center" android:padding="64dp
自定义带标题边框的Layout,像Java-swing的JPanel效果,本例继承LinearLayout,继承其他Layout是一样的过程。
一个小例子,用来解决屏幕的自适应问题。例子里是一个自定义实现比例缩放的layout。