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

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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android使用GridLayout繪制自定義日歷控件

    Android使用GridLayout繪制自定義日歷控件

    這篇文章主要為大家詳細(xì)介紹了Android使用GridLayout繪制自定義日歷控件的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 基于Android實現(xiàn)點擊某個按鈕讓菜單選項從按鈕周圍指定位置彈出

    基于Android實現(xiàn)點擊某個按鈕讓菜單選項從按鈕周圍指定位置彈出

    這篇文章主要介紹了基于Android實現(xiàn)點擊某個按鈕讓菜單選項從按鈕周圍指定位置彈出的相關(guān)資料,需要的朋友可以參考下
    2015-12-12
  • Android學(xué)習(xí)之本地廣播使用方法詳解

    Android學(xué)習(xí)之本地廣播使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Android學(xué)習(xí)之本地廣播使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Android開發(fā)中使用Volley庫發(fā)送HTTP請求的實例教程

    Android開發(fā)中使用Volley庫發(fā)送HTTP請求的實例教程

    這篇文章主要介紹了Android開發(fā)中使用Volley庫發(fā)送HTTP請求的實例教程,包括創(chuàng)建Volley單例的基本知識與取消Request請求的技巧等,需要的朋友可以參考下
    2016-05-05
  • android實現(xiàn)彈出提示框

    android實現(xiàn)彈出提示框

    這篇文章主要為大家詳細(xì)介紹了android實現(xiàn)彈出提示框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • android開發(fā)實現(xiàn)列表控件滾動位置精確保存和恢復(fù)的方法(推薦)

    android開發(fā)實現(xiàn)列表控件滾動位置精確保存和恢復(fù)的方法(推薦)

    下面小編就為大家?guī)硪黄猘ndroid開發(fā)實現(xiàn)列表控件滾動位置精確保存和恢復(fù)的方法(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • Android Rxjava3 使用場景詳解

    Android Rxjava3 使用場景詳解

    本文主要介紹了Android Rxjava3 使用場景詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • Android編程中@id和@+id的區(qū)別分析

    Android編程中@id和@+id的區(qū)別分析

    這篇文章主要介紹了Android編程中@id和@+id的區(qū)別,較為詳細(xì)的分析講述了Android中資源引入的原理及使用@id和@+id引入資源的具體用法,總結(jié)了二者的區(qū)別,需要的朋友可以參考下
    2016-01-01
  • Android觸屏事件和MotionEvent詳解

    Android觸屏事件和MotionEvent詳解

    這篇文章主要介紹了Android觸屏事件和MotionEvent詳解的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下
    2017-10-10
  • Android植物大戰(zhàn)僵尸小游戲

    Android植物大戰(zhàn)僵尸小游戲

    植物大戰(zhàn)僵尸小游戲,無論老少皆愛,非常有意思,具有挑戰(zhàn)性,那么基于代碼是怎么實現(xiàn)的呢?下面通過本文給大家介紹Android植物大戰(zhàn)僵尸小游戲,感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12

最新評論