内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

AndroidUI新組件怎么用-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)Android UI新組件怎么用,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

成都創(chuàng)新互聯(lián)公司專注于企業(yè)成都全網(wǎng)營銷推廣、網(wǎng)站重做改版、昌都網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5高端網(wǎng)站建設(shè)、商城網(wǎng)站開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為昌都等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

Material Dialog

Android UI新組件怎么用

你還在為使用 Material Dialog 去引用第三方的library包么?現(xiàn)在告訴你一個(gè)好消息,其實(shí)Android 在V7包里面已經(jīng)實(shí)現(xiàn)了 Material 風(fēng)格的對話框,并且兼容到底版本了。你只需要在你的代碼中使用V7中的Dialog即可實(shí)現(xiàn)以上圖片效果了。代碼如下

private void showDialog1() {
    android.support.v7.app.AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("讓我們一起飛,我?guī)е?,你帶著錢,來一場說走就走的旅行")
        .setNegativeButton("取消", null)
        .setPositiveButton("確定", null)
        .setTitle("Material Design Dialog")
        .show();
  }

是不是很贊,和之前的Dialog使用無任何差別,媽媽再也不用擔(dān)心我使用Material Dialog對話框了。

SwipeRefreshLayout

Android UI新組件怎么用

原來谷歌已經(jīng)實(shí)現(xiàn)了 Material Design 風(fēng)格的下拉刷新組件,這個(gè)新的組件SwipeRefreshLayout是ViewGroup在V4包下面,你只需按照如下使用:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/swipe_container"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <!--可滑動的組件,比如ScrollView,ListView,GridView,等-->
  <ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  <!--添加自己的內(nèi)容-->

  </ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

SwipeRefreshLayout組件下包裹一個(gè)可滑動的組件即可實(shí)現(xiàn)下拉刷新效果。然后在Java代碼中使用如下:

swipeRefreshLayout = findView(R.id.swipe_container);

    //設(shè)置下拉刷新監(jiān)聽事件
    swipeRefreshLayout.setOnRefreshListener(this);
    //設(shè)置進(jìn)度條的顏色
    swipeRefreshLayout.setColorSchemeColors(Color.RED, Color.BLUE, Color.GREEN);
    //設(shè)置圓形進(jìn)度條大小
    swipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);
    //設(shè)置進(jìn)度條背景顏色
    swipeRefreshLayout.setProgressBackgroundColorSchemeColor(Color.DKGRAY);
    //設(shè)置下拉多少距離之后開始刷新數(shù)據(jù)
    swipeRefreshLayout.setDistanceToTriggerSync(50);

其中包括以下常用方法:

setColorSchemeColors() 設(shè)置進(jìn)度條顏色,可設(shè)置多個(gè)值,進(jìn)度條顏色在這多個(gè)顏色值之間變化setSize() 設(shè)置下拉出現(xiàn)的圓形進(jìn)度條的大小,有兩個(gè)值:SwipeRefreshLayout.DEFAULT 和 SwipeRefreshLayout.LARGEsetProgressBackgroundColorSchemeColor()設(shè)置圓形進(jìn)度條背景顏色。setDistanceToTriggerSync() 設(shè)置手勢操作下拉多少距離之后開始刷新數(shù)據(jù)

總結(jié):當(dāng)然 SwipeRefreshLayout 組件有很多不足之處,比如沒有上拉刷新這個(gè)功能,不過網(wǎng)上已經(jīng)有人實(shí)現(xiàn)了這一效果,想要的可以自己網(wǎng)上搜一把吧。

LinearLayoutCompat

最近在V7包中突然發(fā)現(xiàn) LinearLayoutCompat 組件,處于好奇,百度了一把這個(gè)組件的作用:用于給LinerLayout 中的子元素item之間設(shè)置間隔線的,效果圖如下:

Android UI新組件怎么用 

你還在為給每個(gè)LinerLayout 的item元素添加分割線煩惱么?告訴你,不用煩惱啦!android 給你現(xiàn)成的組件,你只需簡單配置即可。代碼參考如下:

<android.support.v7.widget.LinearLayoutCompat
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="center|center_horizontal"
      android:orientation="vertical"
      app:divider="@drawable/line"
      app:dividerPadding="25dp"
      app:showDividers="middle|beginning|end">

      <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingTop="10dp"
        android:text="CSDN 廢墟的樹"
        android:textSize="20sp"
        android:textStyle="bold" />

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingTop="10dp"
        android:text="CSDN 廢墟的樹"
        android:textSize="20sp"
        android:textStyle="bold" />

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingTop="10dp"
        android:text="CSDN 廢墟的樹"
        android:textSize="20sp"
        android:textStyle="bold" />

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingTop="10dp"
        android:text="CSDN 廢墟的樹"
        android:textSize="20sp"
        android:textStyle="bold" />

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingTop="10dp"
        android:text="CSDN 廢墟的樹"
        android:textSize="20sp"
        android:textStyle="bold" />

      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingTop="10dp"
        android:text="CSDN 廢墟的樹"
        android:textSize="20sp"
        android:textStyle="bold" />

    </android.support.v7.widget.LinearLayoutCompat>

LinearLayoutCompat其實(shí)就是LinerLayout組件,只是為了兼容低版本,所以你必須的引用 V7包下面的LinearLayoutCompat。 LinearLayoutCompat除了擁有LinerLayout原本的屬性之外,主要有如下幾種屬性來實(shí)現(xiàn) 間隔線效果。

app:divider=”@drawable/line” 給分隔線設(shè)置顏色,這里你需要在drawable在定義shape資源,否則將沒有效果??聪旅鎍pp:dividerPadding=”25dp” 給分隔線設(shè)置距離左右邊距的距離。app:showDividers=”middle|beginning|end” 分隔線顯示的位置,有四種參數(shù)值:middle 每個(gè)item之間,beginning最頂端顯示分隔線,end 最底端顯示分隔線,none不顯示間隔線。

注意 這三個(gè)屬性需要使用 xmlns:app=”http://schemas.android.com/apk/res-auto” 命名空間

app:divider=”@drawable/line” 的資源代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="@color/material_blue_grey_800" />
  <!--需要設(shè)置高度,否則不顯示-->
  <size android:height="1px" />
</shape>

總結(jié):以后你還需要自己畫分割線么?看完LinearLayoutCompat組件是不是很高興啊??!哈哈哈

ListPopupWindow

Android UI新組件怎么用 

PopupWindow的簡單實(shí)用,無需更多的去自定義,獲取去確定PopupWindow的位置等,你只需要使用ListPopupWindow就能滿足你簡單的 PopupWindow 彈出框的使用了。直接上代碼:

public void showListPopup(View view) {
    String items[] = {"item1", "item2", "item3", "item4", "item5"};
    final ListPopupWindow listPopupWindow = new ListPopupWindow(this);

    //設(shè)置ListView類型的適配器
    listPopupWindow.setAdapter(new ArrayAdapter<String>(SwipeRefreshActivity.this, android.R.layout.simple_list_item_1, items));

    //給每個(gè)item設(shè)置監(jiān)聽事件
    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(SwipeRefreshActivity.this, "the position is" + position, Toast.LENGTH_SHORT).show();
//        listPopupWindow.dismiss();
      }
    });

    //設(shè)置ListPopupWindow的錨點(diǎn),也就是彈出框的位置是相對當(dāng)前參數(shù)View的位置來顯示,
    listPopupWindow.setAnchorView(view);

    //ListPopupWindow 距錨點(diǎn)的距離,也就是相對錨點(diǎn)View的位置
    listPopupWindow.setHorizontalOffset(100);
    listPopupWindow.setVerticalOffset(100);

    //設(shè)置對話框的寬高
    listPopupWindow.setWidth(300);
    listPopupWindow.setHeight(600);
    listPopupWindow.setModal(false);

    listPopupWindow.show();

  }

根據(jù)以上代碼,你可以做如下事情:

listPopupWindow.setAnchorView(view); 設(shè)置彈出框顯示的位置listPopupWindow.setHorizontalOffset(100);距離錨點(diǎn)View水平距離listPopupWindow.setVerticalOffset(100); 距離錨點(diǎn)View的垂直距離listPopupWindow.setWidth(300);設(shè)置彈出框的大小

不用解釋了吧!代碼都有注釋。望君自己研究然后去手寫代碼,這樣學(xué)習(xí)更快。

PopupMenu

菜單彈出框,效果如下:

Android UI新組件怎么用

代碼如下:

public void showPopupMenu(View view) {
    //參數(shù)View 是設(shè)置當(dāng)前菜單顯示的相對于View組件位置,具體位置系統(tǒng)會處理
    PopupMenu popupMenu = new PopupMenu(this, view);
    //加載menu布局
    popupMenu.getMenuInflater().inflate(R.menu.menu_main, popupMenu.getMenu());
    //設(shè)置menu中的item點(diǎn)擊事件
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
      @Override
      public boolean onMenuItemClick(MenuItem item) {

        return false;
      }
    });
    //設(shè)置popupWindow消失的點(diǎn)擊事件
    popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
      @Override
      public void onDismiss(PopupMenu menu) {

      }
    });

    popupMenu.show();
  }

總結(jié):PopupMenu 相對ListPopupWindow可定制化比較少。

Spinner

Android UI新組件怎么用

流行風(fēng)格的下拉類別組件。你只需要在XML布局中使用 新的style主題即可實(shí)現(xiàn)如上效果

<Spinner
        android:id="@+id/spinner"
        
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></Spinner>

關(guān)于“Android UI新組件怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。

當(dāng)前名稱:AndroidUI新組件怎么用-創(chuàng)新互聯(lián)
文章源于:http://www.rwnh.cn/article2/ccsjic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、電子商務(wù)、網(wǎng)站內(nèi)鏈手機(jī)網(wǎng)站建設(shè)、微信小程序、網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
靖州| 古蔺县| 东方市| 且末县| 云安县| 新化县| 长子县| 秦皇岛市| 若羌县| 武川县| 财经| 禹州市| 穆棱市| 县级市| 兴义市| 永清县| 洛南县| 布拖县| 巴彦淖尔市| 论坛| 靖安县| 普兰县| 资中县| 宁南县| 滦南县| 瑞安市| 沅江市| 宜丰县| 石阡县| 嫩江县| 靖西县| 遵义市| 浦江县| 大邑县| 漳州市| 承德县| 和政县| 涿鹿县| 濮阳市| 湟中县| 安阳市|