国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Android中UI設(shè)計(jì)的一些技巧?。?!

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

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

我們會(huì)在res/drawable目錄下定義一個(gè)資源文件,比如我們本例中要用到的handle.xml,在里面定義三種狀態(tài),每種狀態(tài)對(duì)應(yīng)一張圖片:
代碼如下:
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中的層:
看過《盜夢空間》的人都知道,夢境有多少層,而Android中也有層次之分,在Android中第一層"夢境",我們可以認(rèn)為是壁紙。第二層就是應(yīng)用的Activity,第三層就是放在Activity上的容器(ViewGroup以及它的子類FrameLayout,LinearLayout等布局對(duì)象),當(dāng)然容器中還可以放容器,你也可以放到N層(最多放多少我還沒驗(yàn)證過),總之最后一層就是那些繼承于View的控件了(諸如,Button,TextView等.)
而ListView以及GridView中UI是怎么設(shè)計(jì)的呢,下面我們看一下效果圖:

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

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

第三步:在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控件顯示的內(nèi)容我事先在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;
  }
     
    }
}
第六步:運(yùn)行上述工程,查看效果:
運(yùn)行效果1:

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

ListView正常效果3:

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

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

聯(lián)系客服