欧美三区_成人在线免费观看视频_欧美极品少妇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條評論
主站蜘蛛池模板: 久久久看 | 久久黄色 | 九九久久久 | 九九精品视频在线播放 | 91福利小视频 | 中文一区二区 | 三级日韩 | 精品乱子伦一区二区三区 | 日韩色区| 亚洲热影院| 色屁屁影院www免费 特片网久久 | 国产精品久久人妻无码网站蜜臀 | 国产99久久精品 | 99动漫| 日本激情视频网站w | 亚洲精品免费在线观看 | 色五月视频 | 青草香蕉精品视频在线观看 | 国产成人精品视频播放 | 国产日韩视频 | 嘿咻嘿咻免费区在线观看吃奶 | 久草干 | 精品欧美一区二区三区久久久 | 久久撸视频| 波多野结衣在线网站 | 天天干天天操天天透 | 国产视频高清在线 | 色综合综合在线 | 天堂在线www网亚洲 欧美 日韩 | 小草社区影院 | 激情五月婷婷综合 | bb毛片| 天天操天天干天天操 | 日本无码免费久久久精品 | 久久婷婷色| 欧美大片网站 | 免费在线一区二区 | 国产成人影院 | 极品狂兵电视剧免费观看 | 欧美黑人在线视频 | 999久久久国产精品 成人不卡视频 |