2015-04-11 4 views
-1

Я пытаюсь построить простой макет, но я не в состоянии выполнить простую задачу:Android макет: выровнять текст IMAGEBUTTON

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    android:id="@+id/widget33" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<TextView 
    android:id="@+id/widget43" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TextView" 
    android:layout_alignParentTop="true" 
    android:layout_toRightOf="@+id/widget42" /> 
<ImageButton 
    android:id="@+id/widget42" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" /> 
</RelativeLayout> 

я хотел бы иметь текст справа значка, центрированного по вертикали с размером значка. Я увидел, что android:layout_alignParentTop="true" выравнивает текст на верхней стороне. Я попытался изменить это на другие свойства, но я не могу получить результат (я новичок в этом, так что простите меня, если мне не хватает чего-то глупого).

Итак, я хотел бы получить:


----------
- ИКОНА - ТЕКСТ
----------

и не


---------- TEXT
- ICON -
----------

Спасибо за вашу помощь

ответ

2

Попробуйте :: Это полезно вам

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    android:id="@+id/widget33" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<TextView 
    android:id="@+id/widget43" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TextView" 
    android:layout_marginTop="10dp" 
    android:layout_alignParentTop="true" 
    android:layout_toRightOf="@+id/widget42" /> 
<ImageButton 
    android:id="@+id/widget42" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" /> 
</RelativeLayout> 

Я добавил код на одну строку в вашем TextView:

android:layout_marginTop="10dp" 
0

Попробуйте использовать это:

android:layout_alignBaseline for text: 
android:layout_alignBaseline="@+id/widget42" 
0

Сделать

RelativeLayout 

android:layout_width="wrap_content" 
android:layout_height="wrap_content" > 

и в

TextView 

использования

android:layout_centerInParent="true" 

вместо

android:layout_alignParentTop="true" 
0

Использование ниже кода для решения

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/widget33" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/widget43" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@+id/widget42" 
      android:text="TextView" /> 

     <ImageButton 
      android:id="@+id/widget42" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" /> 

</RelativeLayout> 
2

Поскольку @vijay сказал, что временное решение здесь, я добавил постоянный. Он выглядит одинаково на всех экранах.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/widget33" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ImageButton 
     android:id="@+id/widget42" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" /> 

    <TextView 
     android:id="@+id/widget43" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_toRightOf="@+id/widget42" 
     android:text="TextView" /> 

</RelativeLayout> 
Смежные вопросы