网站建设资讯

NEWS

网站建设资讯

Android界面布局之RelativeLayout-创新互联

Android 的 RelaliveLayout 布局的参数定义:

10多年的交口网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都营销网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整交口建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“交口网站设计”,“交口网站推广”以来,每个客户项目都认真落实执行。

android:layout_above="@id/xxx" --将控件置于给定ID控件之上
android:layout_below="@id/xxx" --将控件置于给定ID控件之下

android:layout_toLeftOf="@id/xxx" --将控件的右边缘和给定ID控件的左边缘对齐
android:layout_toRightOf="@id/xxx" --将控件的左边缘和给定ID控件的右边缘对齐

android:layout_alignLeft="@id/xxx" --将控件的左边缘和给定ID控件的左边缘对齐
android:layout_alignTop="@id/xxx" --将控件的上边缘和给定ID控件的上边缘对齐
android:layout_alignRight="@id/xxx" --将控件的右边缘和给定ID控件的右边缘对齐
android:layout_alignBottom="@id/xxx" --将控件的底边缘和给定ID控件的底边缘对齐
android:layout_alignParentLeft="true" --将控件的左边缘和父控件的左边缘对齐
android:layout_alignParentTop="true" --将控件的上边缘和父控件的上边缘对齐
android:layout_alignParentRight="true" --将控件的右边缘和父控件的右边缘对齐
android:layout_alignParentBottom="true" --将控件的底边缘和父控件的底边缘对齐
android:layout_centerInParent="true" --将控件置于父控件的中心位置
android:layout_centerHorizontal="true" --将控件置于水平方向的中心位置
android:layout_centerVertical="true" --将控件置于垂直方向的中心位置

编程实例:

Android  界面布局之RelativeLayout

定义布局 activity_main.xml

  android:id="@+id/r1"

  android:layout_width="fill_parent"

  android:layout_height="fill_parent"

  android:background="#edab4a" >

  

    android:id="@+id/Shang"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_alignParentTop="true"

    android:layout_centerHorizontal="true"

    android:text="@string/shang" />

  

    android:id="@+id/Xia"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_alignParentBottom="true"

    android:layout_centerHorizontal="true"

    android:text="@string/xia" />

  

    android:id="@+id/Zuo"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_alignParentLeft="true"

    android:layout_centerVertical="true"

    android:text="@string/zuo" />

  

    android:id="@+id/You"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_alignParentRight="true"

    android:layout_centerVertical="true"

    android:text="@string/you" />

  

    android:contentDescription="@string/wutu"

    android:id="@+id/Start"

    android:layout_width="60dip"

    android:layout_height="100dip"

    android:layout_centerInParent="true"

    android:src="@drawable/fengjing" />

字符串资源 sring.xml

  RelativeLayout

  Settings

  Hello world!

  

  

  

  

  无图

  图片说明

主活动  MainActivity.java

package com.malakana.relativelayout;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.ViewGroup;

import android.widget.Button;

import android.widget.EditText;

import android.widget.ImageView;

import android.widget.RelativeLayout;

import android.app.Activity;

public class MainActivity extends Activity {

RelativeLayout r1;

Button shang;

Button xia;

Button zuo;

Button you;

ImageView currButton;

ImageView start;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

r1 = (RelativeLayout) findViewById(R.id.r1);

shang = (Button) findViewById(R.id.Shang);

xia = (Button) findViewById(R.id.Xia);

zuo = (Button) findViewById(R.id.Zuo);

you = (Button) findViewById(R.id.You);

start = (ImageView) findViewById(R.id.Start);

currButton = start;

shang.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

EditText temp = new EditText(MainActivity.this);

temp.setText(R.string.shuoming);

//设置控件位置

RelativeLayout.LayoutParams lp_1 =

new RelativeLayout.LayoutParams(

ViewGroup.LayoutParams.WRAP_CONTENT,95);

lp_1.addRule(RelativeLayout.ABOVE,currButton.getId()); //ABOVE  在currButton之上

lp_1.addRule(RelativeLayout.CENTER_HORIZONTAL,currButton.getId());

//将控件添加到布局中

r1.addView(temp,lp_1);

}});

xia.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

EditText temp = new EditText(MainActivity.this);

temp.setText(R.string.shuoming);

//设置控件位置

RelativeLayout.LayoutParams lp_1 =

new RelativeLayout.LayoutParams(

ViewGroup.LayoutParams.WRAP_CONTENT,95);

lp_1.addRule(RelativeLayout.BELOW,currButton.getId()); //BELOW  在currButton之下

lp_1.addRule(RelativeLayout.CENTER_HORIZONTAL,currButton.getId());

//将控件添加到布局中

r1.addView(temp,lp_1);

}});

zuo.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

EditText temp = new EditText(MainActivity.this);

temp.setText(R.string.shuoming);

//设置控件位置

RelativeLayout.LayoutParams lp_1 =

new RelativeLayout.LayoutParams(

ViewGroup.LayoutParams.WRAP_CONTENT,95);

lp_1.addRule(RelativeLayout.LEFT_OF,currButton.getId()); //LEFT_OF  将控件的右边缘和currButton的左边缘对齐

lp_1.addRule(RelativeLayout.CENTER_VERTICAL,currButton.getId());  //将控件置于垂直方向的中心位置

//将控件添加到布局中

r1.addView(temp,lp_1);

}});

you.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

EditText temp = new EditText(MainActivity.this);

temp.setText(R.string.shuoming);

//设置控件位置

RelativeLayout.LayoutParams lp_1 =

new RelativeLayout.LayoutParams(

ViewGroup.LayoutParams.WRAP_CONTENT,95);

lp_1.addRule(RelativeLayout.RIGHT_OF,currButton.getId()); //RIGHT_OF  将控件的左边缘和currButton的右边缘对齐

lp_1.addRule(RelativeLayout.CENTER_VERTICAL,currButton.getId());  //将控件置于垂直方向的中心位置

//将控件添加到布局中

r1.addView(temp,lp_1);

}});

}

}

效果图:

Android  界面布局之RelativeLayout

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页题目:Android界面布局之RelativeLayout-创新互联
文章来源:http://cdweb.net/article/dspocs.html