由于項(xiàng)目需求菜單寫活,效果如下:
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到新賓網(wǎng)站設(shè)計(jì)與新賓網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、國(guó)際域名空間、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋新賓地區(qū)。

這里的按鈕數(shù)量是可變的.png
由于不是可滑動(dòng)控件,我用的百分比布局做的適配
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ù)量來(lái)吧
linearParams.height = width/firstTypeList.size();//根據(jù)數(shù)量來(lái)吧
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個(gè)還是可以的,如果太多的話還是推薦用RecyclerView。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
本文題目:Android動(dòng)態(tài)添加view的方法示例
標(biāo)題鏈接:http://chinadenli.net/article18/ihphdp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、網(wǎng)站策劃、移動(dòng)網(wǎng)站建設(shè)、服務(wù)器托管、域名注冊(cè)、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)