2016-06-27 2 views
0

Я новичок в андроиде развития, и это мой код (это относительное расположение)как выровнять TextView справа от ImageView

<ImageView 
    android:id="@+id/logo1" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:src="@drawable/telephone1" 
    android:layout_marginTop="10dp" 
    android:layout_below="@id/text4"/> 

<TextView 
    android:id="@+id/text5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="00966-13-8420444" 
    android:fontFamily="sans-serif" 
    android:textSize="20sp" 
    android:layout_toRightOf="@id/logo1" 
    /> 

Я думал, андроид: layout_toRightOf = "@ ID/logo1 является достаточно и текст был справа от изображения (правильно выровнен), но он отображается в верхней части устройства (место изображения внизу, но не на нижнем краю), какую строку кода я должен добавить?

извините за английский. спасибо

+0

Ваш текст фактически выравнивается справа от изображения, только с 0 маржинальной .Try layout_marginLeft и layout_marginTop для TextView. – randy

+1

опубликовать полный XML-макет (вам не хватает родительского тега) – petey

ответ

0

Если я правильно понял ваш вопрос, вы хотите, чтобы ваш текст вне картины, но выравнивается по его центру, попробуйте следующее:

<ImageView 
    android:id="@+id/logo1" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:src="@drawable/telephone1" 
    android:layout_marginTop="10dp" 
    android:layout_below="@id/text4"/> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_gravity="center_vertical"> 

    <TextView 
     android:id="@+id/text5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="00966-13-8420444" 
     android:fontFamily="sans-serif" 
     android:textSize="20sp" 
     android:layout_toRightOf="@id/logo1"/> 
</LinearLayout> 
0

Вы можете сделать макет структуры, как это и затем Перемещение по LinearLayout везде, где вы, как с помощью android:gravity

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="Horizontal"> 

<ImageView 
    android:id="@+id/logo1" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:src="@drawable/telephone1" 
    android:layout_marginTop="10dp"/> 

<TextView 
    android:id="@+id/text5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="00966-13-8420444" 
    android:fontFamily="sans-serif" 
    android:textSize="20sp" 
    /> 

</LinearLayout> 
1

Если я ясно понял ваши вопросы, вы хотите, чтобы отобразить изображение и TextView в одной строке. Кроме того, ваше текстовое изображение - правая сторона изображения. Если это так. Скопируйте/вставьте ниже. Он должен работать

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/logo1" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_marginTop="10dp" 
     android:src="@mipmap/ic_launcher"/> 

    <TextView 
     android:id="@+id/text5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:fontFamily="sans-serif" 
     android:text="00966-13-8420444" 
     android:textSize="20sp" 
     /> 
</LinearLayout> 
0

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

<ImageView 
     android:id="@+id/logo1" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:src="@drawable/telephone1" 
     android:layout_marginTop="10dp" 
     android:layout_below="@id/text4" 
     android:layout_alignParentLeft="true"/> 

    <TextView 
     android:id="@+id/text5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="00966-13-8420444" 
     android:fontFamily="sans-serif" 
     android:textSize="20sp" 
     android:layout_alignParentRight="true" 
     android:layout_toRightOf="@id/logo1" 

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