欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程處理窗口控件大小,形狀,像素等UI元素工具類

 更新時(shí)間:2017年12月01日 11:08:37   作者:LovooGod  
這篇文章主要介紹了Android編程處理窗口控件大小,形狀,像素等UI元素工具類,可實(shí)現(xiàn)像素與dp的轉(zhuǎn)換、窗口寬度設(shè)置、彈出窗口中l(wèi)istview高度設(shè)置等功能,需要的朋友可以參考下

本文實(shí)例講述了Android編程處理窗口控件大小,形狀,像素等UI元素工具類。分享給大家供大家參考,具體如下:

/**
* 處理窗口控件大小,形狀,像素等工具類
*
* @author chen.lin
*
*/
public class UITools {
  /**
  * 把像素轉(zhuǎn)化為dp
  *
  * @param context
  * @param px
  * @return
  */
  public static int px2dip(Context context, float px) {
    float density = context.getResources().getDisplayMetrics().density;
    return (int) (px * density + 0.5f);
  }
  /**
   * 設(shè)置窗體的寬度
   * @param context
   */
  public static void setWinWidth(Activity context) {
    DisplayMetrics metric = new DisplayMetrics();
    context.getWindowManager().getDefaultDisplay().getMetrics(metric);
    LayoutParams p = context.getWindow().getAttributes();
    p.width = (int) (metric.widthPixels * 0.8);
    context.getWindow().setAttributes(p);
  }
  /**
   * 設(shè)置彈出窗口中l(wèi)istview的高度
   *
   * @param listView
   */
  public static void setListViewHeight(ListView listView) {
    // 獲取ListView對(duì)應(yīng)的Adapter
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
      return;
    }
    int totalHeight = 0;
    for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回?cái)?shù)據(jù)項(xiàng)的數(shù)目
      View listItem = listAdapter.getView(i, null, listView);
      listItem.measure(0, 0); // 計(jì)算子項(xiàng)View 的寬高
      totalHeight += listItem.getMeasuredHeight(); // 統(tǒng)計(jì)所有子項(xiàng)的總高度
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    // listView.getDividerHeight()獲取子項(xiàng)間分隔符占用的高度
    // params.height最后得到整個(gè)ListView完整顯示需要的高度
    listView.setLayoutParams(params);
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • android基于SwipeRefreshLayout實(shí)現(xiàn)類QQ的側(cè)滑刪除

    android基于SwipeRefreshLayout實(shí)現(xiàn)類QQ的側(cè)滑刪除

    本篇文章主要介紹了android基于SwipeRefreshLayout實(shí)現(xiàn)類QQ的側(cè)滑刪除,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2017-10-10
  • Android?十六進(jìn)制狀態(tài)管理實(shí)例詳解

    Android?十六進(jìn)制狀態(tài)管理實(shí)例詳解

    這篇文章主要為大家介紹了Android?十六進(jìn)制狀態(tài)管理實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • Android 微信小視頻錄制功能實(shí)現(xiàn)詳細(xì)介紹

    Android 微信小視頻錄制功能實(shí)現(xiàn)詳細(xì)介紹

    這篇文章主要介紹了Android 微信小視頻錄制功能實(shí)現(xiàn)詳解的相關(guān)資料,這里提供了具體的實(shí)現(xiàn)思路及代碼,需要的朋友可以參考下
    2016-11-11
  • Android?DialogFragment使用之基類封裝

    Android?DialogFragment使用之基類封裝

    這篇文章主要介紹了Android?DialogFragment使用之基類封裝示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • Android檢測(cè)Activity或者Service是否運(yùn)行的方法

    Android檢測(cè)Activity或者Service是否運(yùn)行的方法

    下面小編就為大家分享一篇Android檢測(cè)Activity或者Service是否運(yùn)行的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • 30分鐘搞清楚Android Touch事件分發(fā)機(jī)制

    30分鐘搞清楚Android Touch事件分發(fā)機(jī)制

    30分鐘搞清楚Android Touch事件分發(fā)機(jī)制,Touch事件分發(fā)中只有兩個(gè)主角:ViewGroup和View,想要深入學(xué)習(xí)的朋友可以參考本文
    2016-03-03
  • Android 詳解沉浸式狀態(tài)欄的實(shí)現(xiàn)流程

    Android 詳解沉浸式狀態(tài)欄的實(shí)現(xiàn)流程

    沉浸式就是要給用戶提供完全沉浸的體驗(yàn),使用戶有一種置身于虛擬世界之中的感覺。沉浸式模式就是整個(gè)屏幕中顯示都是應(yīng)用的內(nèi)容,沒有狀態(tài)欄也沒有導(dǎo)航欄,用戶不會(huì)被一些系統(tǒng)的界面元素所打擾,讓我們來實(shí)現(xiàn)下網(wǎng)上傳的沸沸揚(yáng)揚(yáng)的安卓沉浸式狀態(tài)欄
    2021-11-11
  • Android  webview和js互相調(diào)用實(shí)現(xiàn)方法

    Android webview和js互相調(diào)用實(shí)現(xiàn)方法

    這篇文章主要介紹了 Android webview和js互相調(diào)用實(shí)現(xiàn)方法的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • Android編程實(shí)現(xiàn)仿iphone抖動(dòng)效果的方法(附源碼)

    Android編程實(shí)現(xiàn)仿iphone抖動(dòng)效果的方法(附源碼)

    這篇文章主要介紹了Android編程實(shí)現(xiàn)仿iphone抖動(dòng)效果的方法,結(jié)合實(shí)例形式分析了仿iphone抖動(dòng)效果的頁面布局及功能實(shí)現(xiàn)技巧,并附帶實(shí)例源碼供讀者下載,需要的朋友可以參考下
    2015-11-11
  • ListView的Adapter使用 之 初學(xué)ArrayAdapter String

    ListView的Adapter使用 之 初學(xué)ArrayAdapter String

    ListView是Android中經(jīng)常會(huì)使用的東西,綁定數(shù)據(jù)對(duì)于初學(xué)者來說,尤其是剛接觸編程的人來說,往往會(huì)覺得很難理解,我上大二的時(shí)候?qū)W的java,但是基本上相當(dāng)于沒有學(xué),什么都沒寫過,真正接觸編程就是開始上手學(xué)android,把這些記錄下來,自己可以回頭看下,也可以讓新手更好的理解
    2013-06-06

最新評(píng)論