Сохраняйте высоту рисования в середине видимого текстового представления

Я использую расширяемый текст, как показано ниже. Я хочу добавить небольшой рисунок справа от него (какая-то стрелка). Эту стрелку легко удерживать в центре по вертикали, когда представление свернуто. Однако, когда я расширяю представление, которое содержит много текста (например, 100 строк), мой рисуемый объект помещается в середину высоты содержимого. Как я могу разместить его в середине видимой высоты?

   <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;
   }
}

person Yarh    schedule 15.08.2014    source источник


Ответы (1)


Не нашел способа добиться этого с помощью текстового представления coupaund, поэтому все еще нужно использовать линейную компоновку.

 <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>
person Yarh    schedule 29.12.2014