2014-10-14 3 views
1

Мне нужно сделать текстовое представление в Tablelayout с иконкой изображения слева до TextView. В таблицеLayout ширина имеет fill_parent, так что вся область является кликабельной.Изображение слева до TextView, Textview должно быть в центре

<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_gravity="top" 
     android:drawablePadding="5dp" 
     android:drawableStart="@drawable/down_arrow" 
     android:gravity="start|center" 
     android:text="@string/hello_world" /> 
</TableLayout> 

Я попытался принести Textview с изображением в центр, но не смог этого сделать. Просьба помочь мне достичь того же.

Благодаря Vikash

This is the output i am getting, I need textview and Image in center

ответ

1

попробовать это:

<TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center"> 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="50dp" 
       android:drawablePadding="5dp" 
       android:drawableStart="@drawable/ic_launcher_0" 
       android:gravity="start|center" 
       android:text="@string/hello_world" /> 
     </TableRow> 
    </TableLayout> 

enter image description here

+0

В этом случае изображение все еще находится в предыдущей позиции. –

+0

Вы хотите, чтобы изображение также было в центре? – Rustam

+0

TextView должен находиться в центре, а значок - только слева. –

0

Используйте это:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#ffffff" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="32dp" 
    android:src="@drawable/app_icon" /> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/imageView1" 
    android:layout_marginBottom="24dp" 
    android:layout_marginLeft="20dp" 
    android:layout_toRightOf="@+id/imageView1" 
    android:text="TextView" /> 

</RelativeLayout> 
+0

Мне нужно использовать только TableLayout. Это требуется для других целей. –

Смежные вопросы