单边圆角的xml毕业论文的致谢怎么写写

Duilib学习笔记《02》— 界面布局
Duilib学习笔记《02》— 界面布局
围观8480次
1. 界面描述XML文件
Duilib主要是通过XML来进行界面的布局配置,程序通过读取并解析XML文件来创建对应的窗体。DuiLib的页面布局分为三类:窗体(Window)、容器(Contain)和控件(Control)。顾名思义窗体就是要创建的窗口,容器则相当于是窗体内的一个子窗体,可以在容器内添加容器或者控件,当然定义的位置也都是相对与容器内的左上顶点;控件就是一些常用的Button、Edit、Label等窗体上的基本元素。
容器经常使用的有VerticalLayout(垂直布局容器)、HorizontalLayout(水平布局容器)、TabLayout(页标签布局容器)、RichEdit(富文本框)、Combo(下拉文本框)、List(列表)
控件经常使用的有Label(标签)、Button(按钮)、Option(选择框)、Edit(文本框)、ScrollBar(滚动条)等等。
首先根节点必须是Window,这个表示窗体,然后在跟节点内可以添加内容。各节点可以添加属性,属性包含 名字、位置、大小、背景色、前景色、背景图片、显示文本、鼠标悬浮提示等等。(注:在duilib中有一份”属性列表.xml”的文件,详细罗列了每个空间对应的属性,方便使用时查阅)
2. 简单空白窗体界面
此处以创建一个简单的空白的灰色背景窗体为例。对应的XML布局文件对应的也就很简单。如下:
&?xml version=&1.0& encoding=&UTF-8&?&
&Window size=&800,600& roundcorner=&4,4&&
&VerticalLayout bkcolor=&#AAA0AAA0&&
&/VerticalLayout&
根据字面意思可以很容易看出XML文件所表示的窗体属性,窗体大小(size)为800X600,窗口圆角大小(roundcorner)为(3,3)等等。
接下来,创建DuilibDemo程序来读取解析该XML文件创建对应的窗体(注:对应的具体实现代码暂不作具体解释,在笔记最后会给出配对的代码方便下载查阅。本节主要是针对XML窗体布局部分,具体代码如何显示后续会具体单独详解),效果如下:
3. 标题栏创建
通过第二步中创建的简单空白窗体,可能发现最终窗体效果和MFC方式创建的并没什么太大区别。因为上述简单窗体的创建只是读取解析XML然后创建对应的窗体,具体的相关消息流程都暂未做处理。所以,接下来,我们通过做一个标题栏的创建来演示说明。
3.1 屏蔽系统标题栏
在此之间,我们得屏蔽掉系统标题栏。在消息处理函数中,我们通过在消息处理函数HandleMessage中对消息WM_NCACTIVATE、WM_NCCALCSIZE、WM_NCPAINT处理来屏蔽系统标题栏,具体屏蔽消息处理代码如下(可在配对的代码中查看):
LRESULT CMainWndDlg::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
if( ::IsIconic(*this) ) bHandled = FALSE;
return (wParam == 0) ? TRUE : FALSE;
LRESULT CMainWndDlg::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
LRESULT CMainWndDlg::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
这样之后运行就会得到一个不带系统标题栏的灰色空白窗体。
3.2 创建自绘标题栏
屏蔽系统标题栏之后,接下来就可以创建自绘标题栏了。其实创建自绘标题栏不需要额外修改程序代码部分,只需要在XML中添加标题栏Caption部分的布局即可。对于标题栏,我们所熟知的主要是分为两部分:左上角的title和右上角的系统按钮。再加上标题栏本身占有一部分区域,而且在该区域可以支持鼠标拖动窗体的,所有在原有的xml文件基础上对应的我们需要添加修改的地方有三处:
3.2.1)区域大小声明。在创建窗体的时候根据需要提前指定窗体可拖动标题栏大小边距。
&Window size=&800,600& caption=&0,0,0,64& roundcorner=&4,4&&
3.2.2)Title区域
&HorizontalLayout name=&captionTitle& childpadding=&6&&
&Control width=&10& /& &!-- 占空位,占据左边10个单位大小空位 --&
&VerticalLayout&
&Control height=&20& /&
&Label text=&Demo演示窗体& textcolor=&#FF447AA1& width=&200&
&/VerticalLayout&
&/HorizontalLayout&
3.2.3)系统按钮区域
&HorizontalLayout name=&captionSysBtn& width=&126& height=&24& inset=&0,1,0,0&&
&Button name=&menuBtn& maxwidth=&26& maxheight=&17& normalimage=&file='sys_dlg_menu.png' source='52,0,78,17'& hotimage=&file='sys_dlg_menu.png' source='26,0,52,17'& pushedimage=&file='sys_dlg_menu.png' source='0,0,26,17'&/&
&Button name=&minBtn& maxwidth=&26& maxheight=&17& normalimage=&file='sys_dlg_min.png' source='52,0,78,17'& hotimage=&file='sys_dlg_min.png' source='26,0,52,17'& pushedimage=&file='sys_dlg_min.png' source='0,0,26,17'&/&
&Button name=&maxBtn& maxwidth=&26& maxheight=&17& normalimage=&file='sys_dlg_max.png' source='52,0,78,17'& hotimage=&file='sys_dlg_max.png' source='26,0,52,18'& pushedimage=&file='sys_dlg_max.png' source='0,0,26,17'&/&
&Button name=&restoreBtn& visible=&false& maxwidth=&26& maxheight=&17& normalimage=&file='sys_dlg_restore.png' source='52,0,78,17'& hotimage=&file='sys_dlg_restore.png' source='26,0,52,17'& pushedimage=&file='sys_dlg_restore.png' source='0,0,26,17'& /&
&Button name=&closeBtn& maxwidth=&45& maxheight=&17& normalimage=&file='sys_dlg_close.png' source='90,0,135,17'& hotimage=&file='sys_dlg_close.png' source='45,0,90,17'& pushedimage=&file='sys_dlg_close.png' source='0,0,45,17'&/&
&/HorizontalLayout&
注意:为了使界面更加美观,引入了一些图片资源。比如窗体背景、按钮图片等等。具体使用方法很简单,参考代码使用即可。虽然界面效果达到了,但细心的人可能会发现,鼠标点击标题栏区域时还是会弹出系统自带的菜单等。这是因为我们目前只是在界面上达到了屏蔽了系统自带标题栏,并自绘标题栏的效果,但消息的处理还没改变。所以此处还需要添加对点击等操作的消息处理,即在HandleMessage中添加对消息WM_NCHITTEST的处理。对应OnNcHitTest分支下的处理函数如下:
LRESULT CMainWndDlg::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
POINT pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam);
::ScreenToClient(*this, &pt);
::GetClientRect(*this, &rcClient);
RECT rcCaption = m_PaintManager.GetCaptionRect();
if( pt.x &= rcClient.left + rcCaption.left && pt.x & rcClient.right - rcCaption.right \
&& pt.y &= rcCaption.top && pt.y & rcCaption.bottom ) {
CControlUI* pControl = static_cast&CControlUI*&(m_PaintManager.FindControl(pt));
if( pControl && _tcscmp(pControl-&GetClass(), _T(&ButtonUI&)) != 0 &&
_tcscmp(pControl-&GetClass(), _T(&OptionUI&)) != 0 &&
_tcscmp(pControl-&GetClass(), _T(&TextUI&)) != 0 )
return HTCAPTION;
return HTCLIENT;
这样一来也就达到了预期的效果。当然,这只是最简单的界面效果,想要得到复杂的界面效果,首先还需要根据实际需要在界面添加相关控件绘制等等。具体的布局可以直接在上述XML文件中继续添加完善;其次,还需要对界面一些控件的消息响应的处理,具体消息效应会在后续章节提到。上述布局完成后对应的效果如下:
4. UIDesigner
Duilib中实际上提供了所见即所得的窗体设计器UIDesigner。如下图所示:
对于习惯了MFC对话框中直接拖控件来布局的人来说或许很喜欢这个设计器。这个设计器同样也是可以直接拖放相关控件来完成布局,最终保存会自动生成对应的XMl文件。如果熟悉了XML布局后,实际上手写起来或许会更方便,而且对于一些复杂的界面布局来说,手动写XML文件应该比用该设计器要方便的多。
5. 补充说明
1)上述的布局只是简单的布局,在布局中很多控件的属性可以参考下载的duilib中的“属性文件.xml”中罗列的信息。
2)全局属性。在上述最终的Demo图片中可以发现字体和默认的有些不一样,实际上是进行了相关设置。对于字体、Default之类的的属性设置具体参考例子代码:
&Font name=&宋体& size=&13& bold=&true& /&
&Font name=&宋体& size=&12& bold=&true& underline=&true&/&
&Font name=&宋体& size=&12& /&
&Font name=&宋体& size=&22& bold=&true&/&
这里我们定义了四种字体样式,序号默认从0开始依次递增。而要具体使用时,如Demo中标题栏的字体设置:
&Label text=&Demo演示窗体& textcolor=&#FF447AA1& width=&200& font=&3& /&
这里font=+就表示Label中的文字使用序号3对应的&Font name=”宋体” size=+ bold=”true”/&这种样式。
3)布局这块,上述只是简单的一个布局,引导大家熟悉。对于如何更好的学会布局,一方面可以随着后续深入学习,进一步熟悉相关控件及属性后,要能灵活运用大到实际例子中;另一方面,一个很好的方法就是查看一些例子,通过例子来学习。对于设计好的布局,可以直接通过UIDesigner来打开XML文件可以很方便的即时查看界面样例。
最后附上本节对应的代码(说明,后续章节都是基于此代码逐步完善)。
&& 本文固定链接:
&& 转载请注明:
如果您觉得这篇文章有用处,请支持作者!鼓励作者写出更好更多的文章!
您可能还会对这些文章感兴趣!
随机文章最近访客点击广告赞助本站一个支持圆角的快速ImageView:RoundedImageView - stephen830 - ITeye技术网站
博客分类:
一个支持圆角的快速ImageView:RoundedImageView
RoundedImageView是一个支持圆角的快速ImageView,基于 实现。
&com.makeramen.RoundedImageView
xmlns:app="/apk/res-auto"
android:id="@+id/imageView1"
android:src="@drawable/photo1"
android:scaleType="fitCenter"
app:riv_corner_radius="30dip"
app:riv_border_width="2dip"
app:riv_border_color="#333333"
app:riv_mutate_background="true"
app:riv_tile_mode="repeat"
app:riv_oval="true" /&
RoundedImageView riv = new RoundedImageView(context);
riv.setScaleType(ScaleType.CENTER_CROP);
riv.setCornerRadius((float) 10);
riv.setBorderWidth((float) 2);
riv.setBorderColor(Color.DKGRAY);
riv.mutateBackground(true);
riv.setImageDrawable(drawable);
riv.setBackground(backgroundDrawable);
riv.setOval(true);
riv.setTileModeX(Shader.TileMode.REPEAT);
riv.setTileModeY(Shader.TileMode.REPEAT);
项目主页:
使用方法:
下载zip包,然后解压。
(1)把红框中的java文件复制到自己的项目中。(将java中用到的R.java路径换成自己项目的R.java包名)
(2)再将res/values/attrs.xml文件内容复制到自己项目的res/values/attrs.xml (注意:如果自己项目已经有这个attrs.xml,只需要将内容合并到自己的attrs.xml中)
(3)下载Picasso的jar库。(没有Picasso库的话,上面复制的java文件会出现错误)
Picasso的jar库下载地址:
点上面的Lastest JAR按钮就可以下载最新的Picasso的jar库。
在下面附件中我上传了一个picasso-2.5.0.jar ,大家也可以下载。
(116.4 KB)
下载次数: 3
stephen830
浏览: 939522 次
来自: 上海
不明白为什么?
有时起作用,有时不起作用!
文章非常好,楼主一再强调最低的sdk问题,但是AndroidM ...圆角PopupWindow对话框和圆角EditText - 乘长风破万里浪 - ITeye技术网站
博客分类:
Android默认的PopupWindow和EditText的外观是矩形框,看起来不是太好,本示例通过设置布局View的背景和PopupWindowd对象的背景,实现有白色圆角边框的对话框效果和圆角文字编辑框。代码如下(关键部分是背景布局XML):
对话框弹出效果图:
package com.
import android.app.A
import android.content.C
import android.os.B
import android.text.InputT
import android.view.G
import android.view.LayoutI
import android.view.V
import android.view.View.OnClickL
import android.widget.B
import android.widget.EditT
import android.widget.PopupW
import android.widget.LinearLayout.LayoutP
public class RoundCorner extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 定义按钮
mButton = (Button) this.findViewById(R.id.Button01);
mButton.setOnClickListener(new ClickEvent());
// 两个圆角文字编辑框
EditText et1 = (EditText) this.findViewById(R.id.roundedtext1);
EditText et2 = (EditText) this.findViewById(R.id.roundedtext2);
et1.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
et2.setInputType(InputType.TYPE_NULL); //不显示软键盘
// 处理按键事件
class ClickEvent implements OnClickListener {
public void onClick(View v) {
if (v == mButton) {
showRoundCornerDialog(RoundCorner.this, RoundCorner.this.findViewById(R.id.Button01));
// 显示圆角对话框
public void showRoundCornerDialog(Context context, View parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// 获取圆角对话框布局View,背景设为圆角
final View dialogView = inflater.inflate(R.layout.popupwindow, null, false);
dialogView.setBackgroundResource(R.drawable.rounded_corners_view);
// 创建弹出对话框,设置弹出对话框的背景为圆角
final PopupWindow pw = new PopupWindow(dialogView, 300, LayoutParams.WRAP_CONTENT, true);
pw.setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_pop));
//注:上面的设背景操作为重点部分,可以自行注释掉其中一个或两个设背景操作,查看对话框效果
//注:上面的设背景操作为重点部分,可以自行注释掉其中一个或两个设背景操作,查看对话框效果
final EditText edtUsername = (EditText) dialogView.findViewById(R.id.username_edit);
final EditText edtPassword = (EditText) dialogView.findViewById(R.id.password_edit);
edtUsername.setHint("用户名..."); // 设置提示语
edtPassword.setHint("密码...");
// 设置提示语
// OK按钮及其处理事件
Button btnOK = (Button) dialogView.findViewById(R.id.BtnOK);
btnOK.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// 设置文本框内容
edtUsername.setText("username");
edtPassword.setText("password");
// Cancel按钮及其处理事件
Button btnCancel = (Button) dialogView.findViewById(R.id.BtnCancel);
btnCancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
pw.dismiss();// 关闭
// 显示RoundCorner对话框
pw.showAtLocation(parent, Gravity.CENTER|Gravity.BOTTOM, 0, 0);
1,圆角对话框的背景布局文件XML。
--------rounded_corners_pop.xml此为PopupWindow的背景布局文件
&?xml version="1.0" encoding="utf-8"?&
&shape xmlns:android="/apk/res/android"&
&solid android:color="#ffffffff" /&
&stroke android:width="3dp" color="#ffff8080" /&
&corners android:radius="10dp" /&
&padding android:left="3dp" android:top="3dp"
android:right="3dp" android:bottom="3dp" /&
--------rounded_corners_view.xml此为对话框内容的背景布局文件
&?xml version="1.0" encoding="utf-8"?&
&shape xmlns:android="/apk/res/android"&
&solid android:color="#ff606060" /&
&stroke android:width="3dp" color="#ffff8080" /&
&corners android:radius="10dp" /&
&padding android:left="5dp" android:top="5dp"
android:right="5dp" android:bottom="5dp" /&
2,圆角文字编辑框的三个布局XML文件
---------rounded_edittext_states.xml
&?xml version="1.0" encoding="utf-8"?&
&selector xmlns:android="/apk/res/android"&
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/rounded_focused" /&
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/rounded_focused" /&
android:state_enabled="true"
android:drawable="@drawable/rounded_edittext" /&
&/selector&
----------rounded_edittext.xml
&?xml version="1.0" encoding="utf-8"?&
&shape xmlns:android="/apk/res/android"
android:shape="rectangle"
android:padding="8dip"&
&solid android:color="#FFFFFF"/&
android:bottomRightRadius="10dip"
android:bottomLeftRadius="10dip"
android:topLeftRadius="10dip"
android:topRightRadius="10dip"/&
-----------rounded_edittext_focused.xml
&?xml version="1.0" encoding="utf-8"?&
&shape xmlns:android="/apk/res/android"
android:shape="rectangle"
android:padding="8dip"&
&solid android:color="#FFFFFF"/&
&stroke android:width="2dip" android:color="#FF0000" /&
android:bottomRightRadius="10dip"
android:bottomLeftRadius="10dip"
android:topLeftRadius="10dip"
android:topRightRadius="10dip"/&
3,对话框的布局文件popupwindow.xml
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical"&
&TextView android:id="@+id/username_view"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:text="用户名"
android:textAppearance="?android:attr/textAppearanceMedium"/&
&EditText android:id="@+id/username_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:capitalize="none"
android:textAppearance="?android:attr/textAppearanceMedium" /&
&TextView android:id="@+id/password_view"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:text="密码"
android:textAppearance="?android:attr/textAppearanceMedium"/&
&EditText android:id="@+id/password_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:capitalize="none"
android:password="true"
android:textAppearance="?android:attr/textAppearanceMedium" /&
&LinearLayout android:id="@+id/LinearLayout01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center"
android:paddingLeft="10dip"
android:paddingRight="10dip"&
&Button android:id="@+id/BtnOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="确定"/&
&Button android:id="@+id/BtnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="取消"/&
&/LinearLayout&
&/LinearLayout&
4,主布局文件 main.xml
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android="/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="10dip"&
&EditText android:id="@+id/roundedtext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="圆角编辑框实例"
android:padding="5dip"
android:background="@drawable/rounded_edittext" /&
&!-- 此View为布局使用 --&
&View android:layout_height="5dip" android:layout_width="fill_parent"/&
&EditText android:id="@+id/roundedtext2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="聚焦可变边框颜色"
android:padding="5dip"
android:paddingTop="30dip"
android:background="@drawable/rounded_edittext_states"/&
&!-- 此View为布局使用 --&
&View android:layout_height="5dip" android:layout_width="fill_parent"/&
&Button android:id="@+id/Button01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="弹出圆角对话框"/&
&/LinearLayout&
注:附件中为完整项目代码实例
下载次数: 580
浏览: 109429 次
来自: 北京
搞得不错 32个赞。。。。。
感谢楼主!!!!
千言万语,就一句:太感谢你了!
非常感谢楼主,非常好用。抄走了。呵呵。android基础6――设置圆角按钮
圆角的按钮实现扁平化的UI很有美感,但是实现起来也不算太难。
在res目录下的drawable-mdpi建立xml文件shape.xml,如下图所示:
&?xml version=&1.0& encoding=&UTF-8&?&&
& & xmlns:android=&/apk/res/android&&
& & android:shape=&rectangle&&&
& & &!-- 填充的颜色 --&&
& & &solid android:color=&#FFFFFF& /&&
& & &!-- 设置按钮的四个角为弧形 --&&
& & &!-- android:radius 弧形的半径 --&&
& & &corners android:radius=&5dip& /&&
&!-- padding:Button里面的文字与Button边界的间隔 --&&
& &android:left=&10dp&&
& &android:top=&10dp&&
& &android:right=&10dp&&
& &android:bottom=&10dp&&
在android:background=&@drawable/shape&就使用了shape.xml资源
&?xml version=&1.0& encoding=&utf-8&?&&
&LinearLayout xmlns:android=&/apk/res/android&&
& & android:orientation=&vertical&&
& & android:layout_width=&fill_parent&&
& & android:layout_height=&fill_parent&&
&TextView & &
& & android:layout_width=&fill_parent& &&
& & android:layout_height=&wrap_content& &&
& & android:text=&@string/hello&&
&Button &&
& & android:id=&@+id/roundButton&&
& & android:text=& 圆角按钮 &&
& & android:layout_width=&wrap_content& &&
& & android:layout_height=&wrap_content& &&
& & android:background=&@drawable/shape&&
&/LinearLayout&&
strings.xml
&?xml version=&1.0& encoding=&utf-8&?&&
&resources&&
& & &string name=&hello&&Hello World, RoundButtonDemoActivity!&/string&&
& & &string name=&app_name&&RoundButtonDemo&/string&&
&/resources&&
RoundButtonDemoActivity.java
package com.android.RoundButtonDemo. &
import android.app.A &
import android.os.B &
import android.view.V &
import android.view.View.OnClickL &
import android.widget.B &
import android.widget.T &
public class RoundButtonDemoActivity extends Activity { &
& & Button roundB &
& & @Override&
& & public void onCreate(Bundle savedInstanceState) { &
& & & & super.onCreate(savedInstanceState); &
& & & & setContentView(R.layout.main); &
& & & & &&
& & & & roundButton=(Button)findViewById(R.id.roundButton); &
& & & //使用匿名类注册Button事件 &
& & & & roundButton.setOnClickListener(new OnClickListener() &
& & & { & & &&
& & & & & & public void onClick(View v) &
& & & & & & { &
& & & & & & & & Toast.makeText(RoundButtonDemoActivity.this, &你点击了圆角按钮&,Toast.LENGTH_LONG).show(); &
& & & & & & } &
& & & & }); &
您对本文章有什么意见或着疑问吗?请到您的关注和建议是我们前行的参考和动力&&
您的浏览器不支持嵌入式框架,或者当前配置为不显示嵌入式框架。

我要回帖

更多关于 简历的自我评价怎么写 的文章

 

随机推荐