[英]Expand textview height inside android custom listview
我有一個帶有文本視圖的自定義列表視圖。 單擊文本視圖時,必須根據可用文本增加行高。 例如,當按下holder.asr_tv_Content時,當前行所在的行以及其他控件的高度必須增加
public class StudentRemarksAdapter extends BaseAdapter {
Context _Context = null;
ArrayList<String> _as_Day;
ArrayList<String> _as_Month;
ArrayList<String> _as_Year;
ArrayList<String> _as_Heading;
ArrayList<String> _as_Content;
ArrayList<String> _as_Values;
LayoutInflater inflater = null;
public StudentRemarksAdapter(Context a_Context,
ArrayList<String> as_Day, ArrayList<String> as_Month,
ArrayList<String> as_Year, ArrayList<String> as_Heading,
ArrayList<String> as_Content, ArrayList<String> as_Values) {
// TODO Auto-generated constructor stub
this._Context = a_Context;
this._as_Day = as_Day;
this._as_Month = as_Month;
this._as_Year = as_Year;
this._as_Heading = as_Heading;
this._as_Content = as_Content;
this._as_Values = as_Values;
inflater = (LayoutInflater) _Context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return _as_Day.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class Holder {
RelativeLayout asr_rl_background;
TextView asr_tv_Day, asr_tv_Month, asr_tv_Year, asr_tv_Heading,
asr_tv_Content;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder = new Holder();
if (convertView == null) {
holder = new Holder();
convertView = inflater.inflate(R.layout.adapter_studentremarks,
null);
holder.asr_rl_background = (RelativeLayout) convertView
.findViewById(R.id.asr_rl_background);
holder.asr_tv_Day = (TextView) convertView
.findViewById(R.id.asr_tv_Day);
setControlsStyle
.SetCustomTextViewStyleForContent(holder.asr_tv_Day);
holder.asr_tv_Month = (TextView) convertView
.findViewById(R.id.asr_tv_Month);
setControlsStyle
.SetCustomTextViewStyleForContent(holder.asr_tv_Month);
holder.asr_tv_Year = (TextView) convertView
.findViewById(R.id.asr_tv_Year);
setControlsStyle
.SetCustomTextViewStyleForContent(holder.asr_tv_Year);
holder.asr_tv_Heading = (TextView) convertView
.findViewById(R.id.asr_tv_Heading);
setControlsStyle
.SetCustomTextViewStyleForContentWithBlackText(holder.asr_tv_Heading);
holder.asr_tv_Heading.setTextSize(18);
holder.asr_tv_Heading.setGravity(Gravity.CENTER | Gravity.LEFT);
holder.asr_tv_Content = (TextView) convertView
.findViewById(R.id.asr_tv_Content);
setControlsStyle
.SetCustomTextViewStyleForContentWithBlackText(holder.asr_tv_Content);
holder.asr_tv_Month.setTextSize(14);
holder.asr_tv_Year.setTextSize(14);
holder.asr_tv_Content.setGravity(Gravity.TOP | Gravity.LEFT);
convertView.setTag(holder);
}
else {
holder = (Holder) convertView.getTag();
}
holder.asr_tv_Day.setText(_as_Day.get(position));
holder.asr_tv_Day.setTextSize(26);
holder.asr_tv_Month.setText(_as_Month.get(position));
holder.asr_tv_Year.setText(_as_Year.get(position));
holder.asr_tv_Heading.setText(_as_Heading.get(position));
holder.asr_tv_Content.setText(_as_Content.get(position));
if (_as_Values.get(position).equals(
_Context.getResources()
.getStringArray(R.array.as_mode_Text)[0])) {
holder.asr_rl_background.setBackgroundColor(_Context
.getResources().getColor(
R.color.asr_tv_positiveicon_bgcolor));
} else {
holder.asr_rl_background.setBackgroundColor(_Context
.getResources().getColor(
R.color.asr_tv_negativeicon_bgcolor));
}
return convertView;
}
}
將視圖高度設置為WRAP_CONTENT
(並對其祖先執行相同的操作)
默認情況下顯示文本時,僅顯示其中一小部分
private static final int MAX_LEN = 22; //choose this yourself
if (text.length() > MAX_LEN) {
textView.setText(text.substring(0, MAX_LEN) + "...");
} else {
textView.setText(text);
}
然后點擊,再次更新完整值
textView.setText(text);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.