流失布局
//`//mls是自定义流失布局的id
package com.example.dell_pc.day07.vview;
import android.content.Context;
import android.text.Layout;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.example.dell_pc.day07.R;
import java.util.ArrayList;
import java.util.List;
public class Tabview extends RelativeLayout {
private LinearLayout mlayout_v;
private TextView mtext;
private LinearLayout view;
public Tabview(Context context) {
super(context);
init(context);
}
public Tabview(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public Tabview(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
public Context context;
private void init(Context context) {
this.context=context;
view =(LinearLayout) View.inflate(context, R.layout.layout_v, null);
mlayout_v=(LinearLayout)view.findViewById(R.id.mlayout_v);
addView(view);
}
private void setlist( List<String> list) {
mlayout_v.removeAllViews();
LinearLayout view1 = (LinearLayout)View.inflate(context, R.layout.layout_h, null);
mlayout_v.addView(view1);
int len=0;
view1.removeAllViews();
for (int i=0;i<list.size();i++){
String s = list.get(i);
len=len+s.length();
if(len>25){
view1 = (LinearLayout)View.inflate(context, R.layout.layout_h, null);
mlayout_v.addView(view1);
len=0;
}
RelativeLayout view2 = (RelativeLayout)View.inflate(context, R.layout.text, null);
mtext=(TextView)view2.findViewById(R.id.mtext);
mtext.setText(s);
view1.addView(view2);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view2.getLayoutParams();
params.weight=1;
params.leftMargin=10;
params.rightMargin=10;
params.topMargin=10;
view2.setLayoutParams(params);
}
}
public void setlistdate(List<String> listdate) {
setlist(listdate);
}
}
`