欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Android中UI設計的一些技巧?。?!

大家好,今天給大家分享的是Android中UI設計的一些技巧,本節內容主要有兩點(diǎn):一是Android按鈕(Button)的UI設計,二是:ListView以及GridView的UI設計。

按鈕的狀態(tài):
我們一般搞UI設計,按鈕通常有三個(gè)狀態(tài):normal(正常狀態(tài));focus(焦點(diǎn)狀態(tài)),pressed(按下?tīng)顟B(tài))。如下圖所示:

我們會(huì )在res/drawable目錄下定義一個(gè)資源文件,比如我們本例中要用到的handle.xml,在里面定義三種狀態(tài),每種狀態(tài)對應一張圖片:
代碼如下:
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>   
<selector xmlns:android="http://schemas.android.com/apk/res/android">   
    <item android:state_window_focused="false"  android:drawable="@drawable/handle_normal" />   
    <item android:state_focused="true" android:drawable="@drawable/handle_focused" />   
    <item android:state_pressed="true" android:drawable="@drawable/handle_pressed" />   
</selector>  
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false"  android:drawable="@drawable/handle_normal" />
    <item android:state_focused="true" android:drawable="@drawable/handle_focused" />
    <item android:state_pressed="true" android:drawable="@drawable/handle_pressed" />
</selector>

而我們使用這個(gè)資源文件的用法只需要引用drawable里的資源文件(android:background="@drawable/handle")代碼如下:
view plaincopy to clipboardprint?
<Button     
    android:id="@+id/handle"     
    android:layout_width="wrap_content"     
    android:layout_height="fill_parent"     
    android:background="@drawable/handle"     
/>   
<Button  
    android:id="@+id/handle"  
    android:layout_width="wrap_content"  
    android:layout_height="fill_parent"  
    android:background="@drawable/handle"  
/>  
Android中的層:
看過(guò)《盜夢(mèng)空間》的人都知道,夢(mèng)境有多少層,而Android中也有層次之分,在A(yíng)ndroid中第一層"夢(mèng)境",我們可以認為是壁紙。第二層就是應用的Activity,第三層就是放在A(yíng)ctivity上的容器(ViewGroup以及它的子類(lèi)FrameLayout,LinearLayout等布局對象),當然容器中還可以放容器,你也可以放到N層(最多放多少我還沒(méi)驗證過(guò)),總之最后一層就是那些繼承于View的控件了(諸如,Button,TextView等.)
而ListView以及GridView中UI是怎么設計的呢,下面我們看一下效果圖:

上圖是一個(gè)ListView的效果圖,正常狀態(tài)下是白色背景黑色字體,當我們點(diǎn)擊一列時(shí)會(huì )出現黃色背景。這一效果是如何做到的呢?
ListView單元格顯示的內容其實(shí)是我們事先定義在Layout目錄下的一個(gè)布局文件,從這個(gè)效果來(lái)看,我們可以看出它一共有三個(gè)“層”
第一層容器(LinearLayout) 背景色為白色:
第二層也是容器(LinearLayout)當按下時(shí),背景色為黃色,把第一層擋住(具體做法可以參照按鈕):
第三層是控件(TextView)。
實(shí)例 :
上面說(shuō)了一些,有些人肯定會(huì )云里霧里,所以我們直接來(lái)個(gè)實(shí)例,實(shí)例做完后,再看一下,效果會(huì )更好,大家按照步驟跟我來(lái):
第一步:首先準備素材,準備三個(gè)按鈕,以及ListView的背景圖(上面三個(gè)按鈕已經(jīng)有了,下面我只貼一個(gè)ListView背景圖片):

第二步:新建一個(gè)Android工程,命名為UIDemo.目錄結構如下圖所示:

第三步:在res目錄下新建一個(gè)drawable文件夾,定義兩個(gè)資源文件一個(gè)是handle.xml另一個(gè)為listview_selected.xml,其中handle.xml代碼已經(jīng)在上面貼出,listview_selected.xml代碼如下:
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>   
<selector xmlns:android="http://schemas.android.com/apk/res/android">   
    <item android:state_pressed="true" android:drawable="@drawable/list_selector_background_pressed" />   
</selector>  
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/list_selector_background_pressed" />
</selector>
第四步:修改main.xml布局文件,這里我用到了SliddingDrawer控件,代碼如下:
view plaincopy to clipboardprint?
<?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"  
    >   
<SlidingDrawer     
     android:id="@+id/slidingdrawer"     
     android:layout_width="fill_parent"     
     android:layout_height="fill_parent"     
     android:orientation="horizontal"     
     android:handle="@+id/handle"     
     android:content="@+id/content">     
      <Button     
             android:id="@+id/handle"     
             android:layout_width="wrap_content"     
             android:layout_height="fill_parent"     
             android:background="@drawable/handle"     
        />   
       <ListView   
             android:id="@+id/content"   
             android:layout_width="fill_parent"     
             android:layout_height="wrap_content"   
       />   
</SlidingDrawer>   
</LinearLayout>  
<?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"
    >
<SlidingDrawer  
     android:id="@+id/slidingdrawer"  
     android:layout_width="fill_parent"  
     android:layout_height="fill_parent"  
     android:orientation="horizontal"  
     android:handle="@+id/handle"  
     android:content="@+id/content">  
      <Button  
             android:id="@+id/handle"  
             android:layout_width="wrap_content"  
             android:layout_height="fill_parent"  
             android:background="@drawable/handle"  
        />
       <ListView
          android:id="@+id/content"
          android:layout_width="fill_parent"  
             android:layout_height="wrap_content"
       />
</SlidingDrawer>
</LinearLayout>

我們這里用到了ListView控件,而我們ListView控件顯示的內容我事先在layout目錄下定義兩個(gè)TextView,命名為listview_layout.xml,代碼如下(這里有三層哦!):
view plaincopy to clipboardprint?
<?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"  
    android:background="#ffffff"      
    >     
    <LinearLayout   
        android:orientation="vertical"  
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent"  
        android:background="@drawable/listview_selected"  
        android:padding="6px"  
    >   
    <TextView   
        android:id="@+id/bookname"     
        android:layout_width="fill_parent"   
        android:layout_height="wrap_content"   
        android:textSize="20px"  
        android:textColor="#000000"  
        />   
    <TextView   
        android:id="@+id/author"     
        android:layout_width="fill_parent"   
        android:layout_height="wrap_content"   
        android:textSize="16px"  
        android:textColor="#000000"  
        />   
        </LinearLayout>   
</LinearLayout>  
<?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"
    android:background="#ffffff"   
    >  
    <LinearLayout
     android:orientation="vertical"
     android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/listview_selected"
        android:padding="6px"
    >
<TextView
  android:id="@+id/bookname"  
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:textSize="20px"
     android:textColor="#000000"
     />
<TextView
  android:id="@+id/author"  
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:textSize="16px"
     android:textColor="#000000"
     />
     </LinearLayout>
</LinearLayout>

第五步:修改主核心程序UIDemo.java,代碼如下:
view plaincopy to clipboardprint?
package com.tutor.uidemo;   
import android.app.Activity;   
import android.os.Bundle;   
import android.view.LayoutInflater;   
import android.view.View;   
import android.view.ViewGroup;   
import android.widget.BaseAdapter;   
import android.widget.ListView;   
import android.widget.TextView;   
public class UIDemo extends Activity {   
      
    private ListView mListView;   
    @Override  
    public void onCreate(Bundle savedInstanceState) {   
        super.onCreate(savedInstanceState);   
        setContentView(R.layout.main);   
           
        setupViews();   
    }   
        
    private void setupViews(){   
        mListView = (ListView)findViewById(R.id.content);   
        mListView.setAdapter(new ListViewAdapter());   
    }   
         
    private class ListViewAdapter extends BaseAdapter{   
        //這里返回10行,ListView有多少行取決于getCount()方法   
        public int getCount() {   
            return 10;   
        }   
        public Object getItem(int arg0) {   
            return null;   
        }   
        public long getItemId(int arg0) {   
            return 0;   
        }   
        public View getView(int position, View v, ViewGroup parent) {   
               
            final LayoutInflater inflater = LayoutInflater.from(getApplicationContext());   
               
            if(v == null){   
                v = inflater.inflate(R.layout.listview_layout, null);   
            }              
            TextView mBookName = (TextView)v.findViewById(R.id.bookname);   
            TextView mBookAuthor = (TextView)v.findViewById(R.id.author);   
               
            mBookName.setText("Android傻瓜教程" + position);   
            mBookAuthor.setText("Frankiewei" + position);   
            return v;   
        }   
           
    }   
}  
package com.tutor.uidemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class UIDemo extends Activity {
   
private ListView mListView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        setupViews();
    }
     
    private void setupViews(){
     mListView = (ListView)findViewById(R.id.content);
     mListView.setAdapter(new ListViewAdapter());
    }
      
    private class ListViewAdapter extends BaseAdapter{
     //這里返回10行,ListView有多少行取決于getCount()方法
  public int getCount() {
   return 10;
  }
  public Object getItem(int arg0) {
   return null;
  }
  public long getItemId(int arg0) {
   return 0;
  }
  public View getView(int position, View v, ViewGroup parent) {
   
   final LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
   
   if(v == null){
    v = inflater.inflate(R.layout.listview_layout, null);
   }   
   TextView mBookName = (TextView)v.findViewById(R.id.bookname);
   TextView mBookAuthor = (TextView)v.findViewById(R.id.author);
   
   mBookName.setText("Android傻瓜教程" + position);
   mBookAuthor.setText("Frankiewei" + position);
   return v;
  }
     
    }
}
第六步:運行上述工程,查看效果:
運行效果1:

點(diǎn)擊按鈕效果2:

ListView正常效果3:

ListView點(diǎn)擊效果4:

PS:上面用到了SliddingDrawer控件以及適配器的內容,如果讀者對上面兩個(gè)不了解的,可以參照本人的其他文章學(xué)習:
Android高手進(jìn)階教程(二)之----Android Launcher抽屜類(lèi)SlidingDrawer的使用!
Android高手進(jìn)階教程(十六)之---Android中萬(wàn)能的 BaseAdapter(Spinner,ListView,GridView)的使用!
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
android開(kāi)發(fā)
Android ListView設置weight無(wú)效
Android 仿QQ主頁(yè)面的實(shí)
LayoutInflater作用及使用
php做接口+android 請求API接口并展示到ListView例子
如何以編程方式獲取在A(yíng)ndroid上的應用程序所花費的時(shí)間
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久