編輯:關於Android編程
復制代碼 代碼如下:
package com.test.mytest.widget;
import java.util.List;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MutipleLabelLayout extends LinearLayout {
public MutipleLabelLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MutipleLabelLayout(Context context) {
super(context);
}
public MutipleLabelLayout(Context context, List<String> list) {
super(context);
mList = list;
mContext = context;
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
init();
}
}, 500);
}
private void init() {
this.setOrientation(LinearLayout.VERTICAL);
LinearLayout row = new LinearLayout(mContext);
row.setOrientation(LinearLayout.HORIZONTAL);
this.addView(row);
int rowWidth = this.getMeasuredWidth();
int viewSumWidth = 0;
for (String label : mList) {
TextView labelView = new TextView(mContext);
labelView.setText(label);
labelView.setPadding(10, 0, 10, 0);
labelView.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
row.addView(labelView);
labelView.measure(0, 0);
viewSumWidth += labelView.getMeasuredWidth();
if (viewSumWidth > rowWidth) {
row.removeView(labelView);
row = new LinearLayout(mContext);
row.setOrientation(LinearLayout.HORIZONTAL);
this.addView(row);
row.addView(labelView);
labelView.measure(0, 0);
viewSumWidth = labelView.getMeasuredWidth();
}
// System.out.println("viewSumWidth: " + viewSumWidth);
// System.out.println("rowWidth: " + rowWidth);
}
}
private List<String> mList;
private Context mContext;
}
先把來源貼上http://zrgiu.com/blog/2011/01/making-your-android-app-look-better/http://www.di
兩周廢寢忘食的創作終於成功了,現在拿出來分享一下。先不說別的看一下程序運行效果圖,我沒怎麼設計ui所以界面不是很好看但是能說明問題~~~現在我們來看看實現這個功能需要些什
引言:去年Android 6.0發布後,其新引入的(Requesting Permissions at Run Time)運行時權限就備受開發者關注,隨著今年國內手機廠商
目前世界有幾十億安卓手機在使用,而大量Android 5.0用戶稱自己設備的耗電速度過快。原版Lollipop當中的確存在Wi-Fi引發的耗電問題,但谷歌已