动态加载View布局实现drawableLeft,drawableRight
来源:互联网 发布:ubuntu 16.04 legacy 编辑:程序博客网 时间:2024/04/30 03:04
父布局
<LinearLayout android:id="@+id/layout_all_chart" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/ll_callon_num" android:layout_marginTop="24dp" android:gravity="center" android:minHeight="120dp" android:orientation="horizontal" > <LinearLayout android:id="@+id/layout1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginLeft="14dp" android:layout_marginRight="5dp" android:layout_weight="1" android:orientation="vertical" > </LinearLayout> <LinearLayout android:id="@+id/layout2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginLeft="5dp" android:layout_weight="1" android:orientation="vertical" > </LinearLayout> </LinearLayout>
子布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="1dp" android:orientation="horizontal" > <ImageView android:id="@+id/img_chart" android:layout_width="9dp" android:layout_height="9dp" android:layout_gravity="center_vertical" android:background="@color/static_color1"/> <TextView android:id="@+id/tv_value" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="2dp" android:layout_gravity="center_vertical" android:textColor="#838a99" android:textSize="14sp"/> <TextView android:id="@+id/tv_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="1dp" android:layout_gravity="center_vertical" android:textColor="#747881" android:textSize="17sp"/></LinearLayout>
代码块
动态添加的View中所要的颜色数组;
private int drawableLeftImg[] = { R.color.static_color1,R.color.static_color2, R.color.static_color3,R.color.static_color4, R.color.static_color5,R.color.static_color6, R.color.static_color7,R.color.static_color8, R.color.static_color9,R.color.static_color10 };
<pre name="code" class="java"><pre name="code" class="java">LinearLayout mLayout1 = (LinearLayout)findViewById(R.id.layout1);
LinearLayout mLayout2 = (LinearLayout)findViewById(R.id.layout2);
</pre>customers是从服务器上获取的JSONArray;<pre name="code" class="java"> for (int i = 0; i < customers.length(); i++) {try {JSONObject customer = (JSONObject) (customers.get(i));LinearLayout layout = new LinearLayout(context);View.inflate(context, R.layout.item_chart, layout);ImageView img = (ImageView) layout.findViewById(R.id.img_static_chart);img.setBackgroundResource(<span style="font-family: Arial, Helvetica, sans-serif;">drawableLeftImg[]</span><span style="font-family: Arial, Helvetica, sans-serif;">[i]);</span>TextView tv = (TextView) layout.findViewById(R.id.tv_statistc_value);TextView num = (TextView) layout.findViewById(R.id.tv_statistc_num);tv.setText(customer.optString("value"));num.setText(customer.optInt("count") + "");LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);//取模,让布局分开左右两边排列int index = i % 2;if (index == 0) {mLayout1.addView(ll, params);} else {mLayout2.addView(ll, params);}} catch (JSONException e) {e.printStackTrace();}
0 0
- 动态加载View布局实现drawableLeft,drawableRight
- Android动态布局,并动态为TextView控件设置drawableLeft、drawableRight等属性添加图标
- Android动态布局,并动态为TextView控件设置drawableLeft、drawableRight等属性添加图标
- View代码设置drawableLeft,drawableRight,drawableTop,drawableBottom
- Android控件设置——动态View的drawableLeft/ drawableRight/drawableTop/drawableBottom
- 动态设置drawableTop,drawableLeft,drawableRight,drawableBottom
- android 动态设置drawableTop,drawableLeft,drawableRight,drawableBottom.
- TextView之drawableLeft/drawableRight代码实现
- 自定义EditText 实现drawableRight/drawableLeft 点击事件
- 绝对能用-动态设置textview的drawableleft、drawableright、drawabletop、drawablebottom
- Android中动态设置TextView的drawableLeft和drawableRight的时候图片未出现
- Android动态布局(TextView-drawableLeft)
- Android 实现布局动态加载
- Android 实现布局动态加载
- ANDROID 实现布局动态加载
- 自定义View实现TextView中的DrawableLeft缺陷
- 代码中设置drawableLeft以及drawableRight
- 设置drawableTop、drawableLeft、drawableRight、drawableBottom图片大小
- java excel转dbf
- 【学习笔记】求三个数的中间值
- ListView优化(三) 【来自知乎上的汇总,很有见地!!】
- jsp 页面刷新,EasyUI刷新、加载
- 回收废旧镁铬砖便宜了谁?
- 动态加载View布局实现drawableLeft,drawableRight
- RAID入门一页通,最全的RAID技术、原理图解
- 【tarjan】【桥】
- int与Integer的区别
- C++函数返回多个参数
- Windows系统下查看端口占用
- JQuery级联下拉框的实现
- SM30 标准程序 添加事件、checkbox 等客制化需求
- DFS