2016-07-16 9 views
0

Ich versuche, eine Textansicht in Bildmitte anzuzeigen, aber nicht in LinearLayout.
Wie TextView in Bildmitte ausrichten

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

<ImageView 
    android:id="@+id/kurtis" 
    android:layout_width="0dp" 
    android:layout_height="325dp" 
    android:layout_weight="0.5" 
    android:scaleType="fitXY" 
    android:src="@mipmap/kurtis" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_text="Testing" /> 

<ImageView 
    android:id="@+id/salwars" 
    android:layout_width="0dp" 
    android:layout_height="325dp" 
    android:layout_marginLeft="10dp" 
    android:layout_weight="0.5" 
    android:scaleType="fitXY" 
    android:src="@mipmap/salwar" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_text="Testing"/> 

Jeder habe Idee mir bitte helfen.
Ich habe meine Frage bearbeitet, das ist mein Problem.

+0

Ich werde vorschlagen, dass Sie Relative Layout verwenden und dann in layout_centerInParent ausgerichtet haben. –

Antwort

3

Sie könnten zum Beispiel verwenden RelativeLayout Ihre TextView über die ImageView zum Zentrum:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="325dp" 
     android:layout_weight="0.5"> 

     <ImageView 
      android:id="@+id/kurtis" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="fitXY" 
      android:src="@mipmap/salwar"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_text="Testing"/> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="325dp" 
     android:layout_weight="0.5"> 

     <ImageView 
      android:id="@+id/salwars" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="fitXY" 
      android:src="@mipmap/salwar"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_text="Testing"/> 
    </RelativeLayout> 
</LinearLayout> 
+0

Es funktioniert Danke – vinoth12594

+0

Gern geschehen. Außerdem sollten Sie Ihr Bild in die ziehbaren Ordner und nicht in die Mipmap einfügen. Mipmap ist speziell für Launcher-Symbole. – earthw0rmjim

1

Sie FrameLayout dafür verwenden können. Es zentriert alle seine Kinder, wie:

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

    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="325dp" 
     android:layout_marginRight="10dp" 
     android:layout_weight="1"> 

     <ImageView 
      android:id="@+id/kurtis" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="10dp" 
      android:scaleType="fitXY" 
      android:src="@mipmap/kurtis" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:text="Testing" 
      android:textSize="18sp" /> 

    </FrameLayout> 

    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="325dp" 
     android:layout_weight="1"> 

     <ImageView 
      android:id="@+id/salwar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="10dp" 
      android:scaleType="fitXY" 
      android:src="@mipmap/salwar" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:text="Testing" 
      android:textSize="18sp" /> 

    </FrameLayout> 

</LinearLayout> 
+0

Vielen Dank für Ihre Wiederholung – vinoth12594

Verwandte Themen