¿Es posible escalar drawableleft & drawableright en textview?

Tengo la lista con el artículo es un TextView ; Y usando drawableleft & drawableright para beutify el TextView . El problema es que, siempre que el texto en textview es mayor, drawableleft & drawableleft no TextView automáticamente basado en la altura de TextView .

¿Es posible escalar la altura de drawableleft & drawableright en textview? (Yo estaba usando 9 imágenes de parches)

Textview drawableleft & drawableright problema de altura

Esto podría ayudarte. Hay dos propiedades scaleX y scaleY

El código a continuación reducirá la imagen y el texto con un 30%. Por lo tanto, tienes que aumentar el tamaño de la fuente con tantos "sp", de modo que cuando se vuelva a clasificar según el tamaño (escalado) se ajuste a la "sp" que prefieras.

Ejemplo. Si establezco la fuente a 18, entonces el 30% de los 18 es 5.4sp, por lo que aproximadamente, este es el valor que estoy apuntando a, porque cuando se pone a escala, se convertiría en 13sp

 <TextView android:textSize="18sp" android:scaleX="0.7" android:scaleY="0.7" 

Lo último que se debe hacer es establecer CompundDrawable.

 tview.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.xxx), null, null, null); 

He resuelto un equivalente usecase mediante la introducción de un ScaleDrawable y la ScaleDrawable su. .getIntrisicHeight() para que sea por lo menos la altura TextView . La parte TextView.addOnLayoutChangeListener , necesaria para volver a vincular el Drawable en un cambio de tamaño TextView funciona con API11 +

 Drawable underlyingDrawable = new BitmapDrawable(context.getResources(), result); // Wrap to scale up to the TextView height final ScaleDrawable scaledLeft = new ScaleDrawable(underlyingDrawable, Gravity.CENTER, 1F, 1F) { // Give this drawable a height being at // least the TextView height. It will be // used by // TextView.setCompoundDrawablesWithIntrinsicBounds public int getIntrinsicHeight() { return Math.max(super.getIntrinsicHeight(), competitorView.getHeight()); }; }; // Set explicitly level else the default value // (0) will prevent .draw to effectively draw // the underlying Drawable scaledLeft.setLevel(10000); // Set the drawable as a component of the // TextView competitorView.setCompoundDrawablesWithIntrinsicBounds( scaledLeft, null, null, null); // If the text is changed, we need to // re-register the Drawable to recompute the // bounds given the new TextView height competitorView.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { competitorView.setCompoundDrawablesWithIntrinsicBounds(scaledLeft, null, null, null); } }); 

No encontré el camino. Pero que muestra se ve como una lista de elementos. Cada elemento sería LinearLayout horizontal con imagesView de izquierda a derecha y el texto en el centro. La dimensión de la imagen hace un android: scaleType = "fitXY" para ajust la altura del tamaño a la altura del textview. Si no quiere deformar la imagen use scaleType = "CENTER_INSIDE". http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

 <LinearLayout android:layout_width="fill_parent" android:id="@+id/HeaderList" android:layout_gravity="top" android:layout_height="wrap_content" > <ImageView android:id="@+id/backImg" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerInParent="true" android:adjustViewBounds="true" android:background="@color/blancotransless" android:src="@drawable/header" android:scaleType="fitXY" > </ImageView> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/NameText" android:text="The time of prayer" android:textColor="#FFFFFF" android:textSize="30sp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:paddingLeft="4dp" android:paddingTop="4dp" /> <ImageView android:id="@+id/backImg" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerInParent="true" android:adjustViewBounds="true" android:background="@color/blancotransless" android:src="@drawable/header" android:scaleType="fitXY" > </ImageView> </LinearLayout> 

Sólo haz fondo de 9 trayectorias repitiendo este patrón.

Y también parece que será mejor ver en caso de que el patrón se aplicará a la lista, no al elemento individual.

Por favor, pruebe este código. Esto puede ayudarle.

 Drawable TextViewDrawable = context.getResources().getDrawable(imageId); TextViewDrawable.setBounds(0, 0, TextViewDrawable.getIntrinsicWidth(), TextViewDrawable.getIntrinsicHeight()); text_view.setCompoundDrawables(left, top, right, bottom); 

Espero que esto ayude

 Textview tv = (TextView) findViewById(R.id.tv_dummy) int imageResource = R.mipmap.ic_image; Drawable drawable = ContextCompat.getDrawable(context, imageResource); int pixelDrawableSize = (int)Math.round(tv.getLineHeight() * 0.7); // Or the percentage you like (0.8, 0.9, etc.) drawable.setBounds(0, 0, pixelDrawableSize, pixelDrawableSize); // setBounds(int left, int top, int right, int bottom), in this case, drawable is a square image tv.setCompoundDrawables( null, //left null, //top drawable, //right null //bottom ); 
  • Custom TextView en android con diferentes palabras de color
  • Cómo ajustar la altura de línea en TextView con varios tamaños de tipo?
  • ¿Cómo establecer el texto dentro de TextView para que esté en dos líneas?
  • Configuración de un ancho de TextView en java
  • TextView muestra "false" en lugar de texto de recurso
  • Android: matriz de vistas de texto
  • Obtener texto seleccionado de TextView
  • Cómo cambiar el color de fondo de TextView a valor inicial
  • Cree programaticamente TextView con elipsis
  • ¿Cómo puedo mostrar caracteres especiales (como & ndash;) en TextView?
  • El fondo de TextView se está estirando
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.