欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Android之布局

系統 1909 0
? Android布局是應用界面開發的重要一環,在Android中,共有五種布局方式,分別是:LinearLayout (線性布局),FrameLayout(框架布局),AbsoluteLayout(絕對布局),RelativeLayout(相對布局),TableLayout(表格布局)。
一、LinearLayout
他首先是一個一個從上往下羅列在屏幕上。每一個LinearLayout里面又可分為垂直布局(android:orientation="vertical")和水平布局(android:orientation="horizontal" )。當垂直布局時,每一行就只有一個元素, 多個元素依次垂直往下;水平布局時,只有一行,每一個元素依次向右排列。

Android之布局
?
      <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <Button android:text="Up" 
        android:id="@+id/Button03" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"></Button>
        
    <LinearLayout 
        android:orientation="horizontal" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">        
    <Button android:text="left" 
        android:id="@+id/Button01" 
        android:width="120px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></Button>    
    <Button 
        android:text="right" 
        android:id="@+id/Button02" 
        android:width="120px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></Button>
    </LinearLayout>
</LinearLayout>
    
二、TableLayout
類似于Html每行一個TableRow,可以放置0或者多個控件

Android之布局
?
      <?xml version="1.0" encoding="utf-8"?>
<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TableRow android:gravity="center">
      <Button 
            android:text="Text1" 
            android:id="@+id/Button01" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content">
       </Button>
    </TableRow>
    <TableRow android:gravity="center">
        <TextView android:text="第一行第0列" 
                  android:layout_width="wrap_content" 
                  android:layout_height="wrap_content"></TextView>
        <TextView android:text="第一行第1列" 
                  android:layout_width="wrap_content" 
                  android:layout_height="wrap_content"></TextView>
           <Button 
            android:text="Text2" 
            android:id="@+id/Button01" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content">
       </Button>
    </TableRow>
     <TableRow android:gravity="center">
        <TextView android:text="第二行第0列" 
                  android:layout_width="wrap_content" 
                  android:layout_height="wrap_content"></TextView>
        <TextView android:text="第二行第1列" 
                  android:layout_width="wrap_content" 
                  android:layout_height="wrap_content"></TextView>
    </TableRow>
</TableLayout>
    
?

三、RelativeLayout

不用像LinearLayout一樣在xml把控件按照順序寫下,當然按照順序寫下方便查看,如果是自己選的的順序,直接寫下也可以的。
?相對布局可以理解為某一個元素為參照物,來定位的布局方式。

android:layout_方向 = id 表示 在這個id對應的控件的方向上(上|下)

android:layout_align方向 = id 表示和這個控件的(上下左右)對齊

android: layout_to方向Of = id 表示在這個控件的 左或者右


Android之布局
?

      <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
     <Button
          android:id="@+id/btnmiddle"
          android:text="Middle"
          android:layout_width="200px"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true">     
     </Button>
      <Button
          android:id="@+id/btnup"
          android:text="Up"
          android:layout_width="100px"
          android:layout_height="wrap_content"          
          android:layout_above="@id/btnmiddle"
          android:layout_alignLeft="@id/btnmiddle">     
     </Button>
      <Button
          android:id="@+id/btndown"
          android:text="down"
          android:layout_width="100px"
          android:layout_height="wrap_content"          
          android:layout_below="@id/btnmiddle"
          android:layout_alignRight="@id/btnmiddle">     
     </Button>
       <Button
          android:id="@+id/btnfirst"
          android:text="first"
          android:layout_width="100px"
          android:layout_height="wrap_content"          
          android:layout_above="@id/btnup"
          android:layout_alignLeft="@id/btnmiddle">     
     </Button>
</RelativeLayout>
    

四、AbsoluteLayout
   AbsoluteLayout 這個布局方式很簡單,主要屬性就兩個 layout_x 和 layout_y 分別定義 這個組件的絕對位置。 即,以屏幕左上角為(0,0)的坐標軸的x,y值, 當向下或向右移動時,坐標值將變大。AbsoluteLayout 沒有頁邊框,允許元素之間互相重疊(盡管不推薦)。


Android之布局
?

      <?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  
  <TextView 
       android:layout_width="wrap_content" 
       android:text="UserName:" 
       android:layout_height="wrap_content" 
       android:id="@+id/tvName" 
       android:layout_y="20dip" 
       android:layout_x="50dip">
       </TextView>
   <TextView 
       android:layout_width="wrap_content" 
       android:text="Password:" 
       android:layout_height="wrap_content" 
       android:id="@+id/tvPassword" 
       android:layout_y="100dip" 
       android:layout_x="55dip">
       </TextView>
       
   <EditText
       android:layout_width="150px" 
       android:layout_height="wrap_content" 
       android:id="@+id/tvPassword" 
       android:layout_y="10dip" 
       android:layout_x="120dip">
       </EditText>
   <EditText
       android:layout_width="150px" 
       android:layout_height="wrap_content" 
       android:id="@+id/tvPassword" 
       android:layout_y="90dip" 
       android:layout_x="120dip">
       </EditText>
</AbsoluteLayout>
    

五、FrameLayout

它被定制為你屏幕上的一個空白備用區域,之后你可以在其中填充一個單一對象 — 比如,一張你要發布的圖片。所有的子元素將會固定在屏幕的左上角;你不能為FrameLayout中的一個子元素指定一個位置。后一個子元素將會直接在前一個子元素之上進行覆蓋填充,把它們部份或全部擋住(除非后一個子元素是透明的)

用一個例子解決

通過點擊來更換圖片


Android之布局

      package com.example.linearlayouttext;


import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity {
    private   String TAG = "FramLayoutTestActivity";
    private ImageView image1;
    private ImageView image2;
    private ImageView image3;
    private List<ImageView> list;

    private int count=0;


        /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	//關聯
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        image1=(ImageView)findViewById(R.id.image1);
        image2=(ImageView)findViewById(R.id.image2);
        image3=(ImageView)findViewById(R.id.image3);
        //建了一個list用來存儲圖片
        list=new ArrayList<ImageView>();
        list.add(image1);
        list.add(image2);
        list.add(image3);
    }
    	//監聽 用來更換圖片
        @Override
        public boolean onTouchEvent(MotionEvent event) {
                // TODO Auto-generated method stub
                if(event.getAction()==MotionEvent.ACTION_DOWN)
                {
                               showImage();
                }
                
                return super.onTouchEvent(event);
        }
        private void showImage()
        {
                image1.setVisibility(View.VISIBLE);
                count=count%3;
                for(ImageView i:list)
                {
                        i.setVisibility(View.INVISIBLE);
                }
                list.get(count).setVisibility(View.VISIBLE);
                count++;
        }

}
    

?

      <?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#897753"
    >
    <ImageView 
        android:id="@+id/image1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="invisible"
        android:src="@drawable/flower"/>
    <ImageView 
        android:id="@+id/image2"
        android:visibility="invisible"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/f2"/>
    <ImageView 
        android:id="@+id/image3"
        android:visibility="invisible"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/f3"/>

</FrameLayout>
    

?
?

Android之布局


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国内真实迷j下药在线观看 人人艹逼 | 欧美极品欧美精品欧美视频 | 在线欧美日韩国产 | 国产精品原创巨作av | 日韩国产一区二区三区 | 国产高清一区二区 | 九九视频在线观看 | 日韩精品久久久久 | 欧洲一级视频 | 日韩欧美精品在线观看 | 欧美一区二区三 | 99re在线| 亚洲激情一区二区 | 视频一区欧美 | 欧美在线观看视频 | 成年人网站在线免费观看 | 草莓福利视频 | 欧美一区二区大片 | 黄网站在线播放 | 久操欧美 | 色综合视频 | 欧美a级成人淫片免费看 | 老汉色影院 | 国产精品伊人 | 国产精品v欧美精品∨日韩 一级免费黄色免费片 | 日韩爽爽爽视频免费播放 | 羞羞色院91蜜桃在线观看 | 排球少年第五季樱花动漫免费观看 | 无码AV免费一区二区三区A片 | 日韩精品一区二区三区免费观看 | 国产羞羞网站 | av黄色在线| 国产精品视频网站 | 一区二区三区四区五区中文字幕 | 桥本有菜免费av一区二区三区 | 欧美日韩国产综合视频在线看 | 久久网页 | 亚洲欧美v视色一区二区 | 奇米影视亚洲春色 | 韩国午夜电影 | 国产精品综合色区在线观看 |