我正在使用如下的可扩展textview。我想在它的右边添加一个小的drawable(某种箭头)。当视图折叠时,很容易将此箭头保持在垂直中心。但是,当我展开包含大量文本(如100行)的视图时,我的drawable被放置在内容高度的中间。如何将它放在可见高度的中间?
<LinearLayout
android:id="@+id/tes5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dip"
android:gravity="center_vertical"
android:layout_marginRight="16dip"
android:layout_marginTop="6dip"
android:orientation="horizontal" >
<bigdig.yarh.ellotv.widget.ExpandableTextView
android:id="@+id/tv_artist_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/gray" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/more_arrow_icon" />
</LinearLayout>
ExpandableTextView类
/**
* User: Bazlur Rahman Rokon
* Date: 9/7/13 - 3:33 AM
*/
public class ExpandableTextView extends TextView {
private static final int DEFAULT_TRIM_LENGTH = 200;
private static final String ELLIPSIS = ".....";
private CharSequence originalText;
private CharSequence trimmedText;
private BufferType bufferType;
private boolean trim = true;
private int trimLength;
public ExpandableTextView(Context context) {
this(context, null);
}
public ExpandableTextView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
this.trimLength = typedArray.getInt(R.styleable.ExpandableTextView_trimLength, DEFAULT_TRIM_LENGTH);
typedArray.recycle();
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
trim = !trim;
setText();
requestFocusFromTouch();
}
});
}
private void setText() {
super.setText(getDisplayableText(), bufferType);
}
private CharSequence getDisplayableText() {
return trim ? trimmedText : originalText;
}
@Override
public void setText(CharSequence text, BufferType type) {
originalText = text;
trimmedText = getTrimmedText(text);
bufferType = type;
setText();
}
private CharSequence getTrimmedText(CharSequence text) {
if (originalText != null && originalText.length() > trimLength) {
return new SpannableStringBuilder(originalText, 0, trimLength + 1).append(ELLIPSIS);
} else {
return originalText;
}
}
public CharSequence getOriginalText() {
return originalText;
}
public void setTrimLength(int trimLength) {
this.trimLength = trimLength;
trimmedText = getTrimmedText(originalText);
setText();
}
public int getTrimLength() {
return trimLength;
}
}
答案 0 :(得分:0)
没有找到使用复合textview实现它的方法,所以仍然必须使用线性布局
<LinearLayout
android:id="@+id/ll_favorite_box"
android:layout_width="0dip"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/im_favorite_indicator"
android:layout_width="wrap_content"
android:layout_height="12dip"
android:layout_marginLeft="8dip"
android:layout_marginRight="4dip"
android:scaleType="centerInside"
android:src="@drawable/star_selected_icon" />
<TextView
android:id="@+id/tv_like_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip"
android:text="1000,0b"
android:textColor="@color/black_text_60"
android:textSize="16sp" />
</LinearLayout>