首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将可绘制高度保持在可见文本视图的中间。

将可绘制高度保持在可见文本视图的中间。
EN

Stack Overflow用户
提问于 2014-08-15 14:28:55
回答 1查看 109关注 0票数 0

我使用的是可扩展的文本视图,如下所示。我想在它的右边(某种箭头)添加一个小的、可绘制的。当视图被折叠时,很容易将该箭头保持在垂直中心。但是,当我展开包含大量文本(如100行)的视图时,可绘制的内容被放置在内容高度的中间。我怎样才能把它放在可见高度的中间?

代码语言:javascript
复制
   <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类

代码语言:javascript
复制
/**
* 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;
   }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-29 10:04:43

没有找到一种方法来实现它,所以仍然必须使用线性布局。

代码语言:javascript
复制
 <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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25328273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档