最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android動態(tài)添加view的方法示例

 更新時間:2017年10月20日 09:04:47   作者:楊帥  
本篇文章主要介紹了Android動態(tài)添加view的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

由于項目需求菜單寫活,效果如下:

這里的按鈕數(shù)量是可變的.png

由于不是可滑動控件,我用的百分比布局做的適配

 LinearLayout typeLayout = (LinearLayout) headerView.findViewById(R.id.layout_type);
 final List<FirstTypeEntity.DataBean> firstTypeList = entity.getData();
 for (int i = 0;i<firstTypeList.size();i++){
    WindowManager wm = (WindowManager) getContext()
        .getSystemService(Context.WINDOW_SERVICE);
    int width = wm.getDefaultDisplay().getWidth();
    int height = wm.getDefaultDisplay().getHeight();
    View view = View.inflate(getActivity(),R.layout.item_first_type,null);
    LinearLayout tab = (LinearLayout) view.findViewById(R.id.tab);
    LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) tab.getLayoutParams(); 
    linearParams.width = width/firstTypeList.size();//根據(jù)數(shù)量來吧
    linearParams.height = width/firstTypeList.size();//根據(jù)數(shù)量來吧
    tab.setLayoutParams(linearParams); //使設(shè)置好的布局參數(shù)應(yīng)用到控件
 }

item_first_type代碼:

<com.zhy.android.percent.support.PercentLinearLayout
    android:id="@+id/tab"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:background="@drawable/selector_choose_white">
    <ImageView
      android:id="@+id/iv"
      android:layout_width="0dp"
      app:layout_widthPercent="45%h"
      android:layout_height="0dp"
      app:layout_heightPercent="45%h"
      android:src="@mipmap/first_newenergy_tab"/>
    <TextView
      android:id="@+id/tv"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      app:layout_heightPercent="20%h"
      android:text="新能源"
      android:textColor="@color/black_my"
      app:layout_textSizePercent="12%"
      android:gravity="center"
      android:maxLines="1"
      android:ellipsize="end"/>
  </com.zhy.android.percent.support.PercentLinearLayout>

layout_type代碼:

<com.zhy.android.percent.support.PercentLinearLayout
    android:id="@+id/layout_type"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@color/white">
</com.zhy.android.percent.support.PercentLinearLayout>

這種寫法數(shù)量一般3-6個還是可以的,如果太多的話還是推薦用RecyclerView。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

分宜县| 酒泉市| 闵行区| 福州市| 成安县| 淮滨县| 台山市| 江永县| 庆云县| 紫金县| 永新县| 依安县| 永德县| 德阳市| 闸北区| 长葛市| 安塞县| 汨罗市| 融水| 甘洛县| 肥城市| 耿马| 竹山县| 包头市| 松阳县| 白玉县| 苍山县| 绍兴市| 屯昌县| 碌曲县| 新晃| 兖州市| 阿拉善左旗| 丘北县| 岳阳市| 江西省| 赤城县| 镇巴县| 杭锦后旗| 防城港市| 眉山市|