国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

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

2019-12-12 01:34:49
字體:
來源:轉載
供稿:網友

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

/*** 處理窗口控件大小,形狀,像素等工具類** @author chen.lin**/public class UITools {  /**  * 把像素轉化為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);  }  /**   * 設置窗體的寬度   * @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);  }  /**   * 設置彈出窗口中listview的高度   *   * @param listView   */  public static void setListViewHeight(ListView listView) {    // 獲取ListView對應的Adapter    ListAdapter listAdapter = listView.getAdapter();    if (listAdapter == null) {      return;    }    int totalHeight = 0;    for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回數據項的數目      View listItem = listAdapter.getView(i, null, listView);      listItem.measure(0, 0); // 計算子項View 的寬高      totalHeight += listItem.getMeasuredHeight(); // 統計所有子項的總高度    }    ViewGroup.LayoutParams params = listView.getLayoutParams();    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));    // listView.getDividerHeight()獲取子項間分隔符占用的高度    // params.height最后得到整個ListView完整顯示需要的高度    listView.setLayoutParams(params);  }}

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

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洮南市| 巴里| 白水县| 湄潭县| 西吉县| 江川县| 望江县| 朝阳市| 石狮市| 大足县| 云霄县| 航空| 衡水市| 永胜县| 安达市| 沙湾县| 枞阳县| 淄博市| 普宁市| 湘西| 虎林市| 汝阳县| 安岳县| 马龙县| 永善县| 高碑店市| 册亨县| 平顺县| 蒙阴县| 芦山县| 聊城市| 沛县| 绥德县| 台湾省| 宣恩县| 桐梓县| 六枝特区| 永兴县| 和田市| 舟曲县| 依兰县|