Bild zentrieren in xml Datei

  • 8 Antworten
  • Letztes Antwortdatum
T

Tai

Neues Mitglied
0
hi, ich möchte gerne ein Bild zentrieren bei mir in der main.xml Datei. Wie ist dafür der Befehl? LG
 
ein wichtiger befehl dafür ist
android:gravity="xxx"

xxx kannst durch viele werte ersetzen: zB center, center_horizontal, ...
 
dann zeig mal deinen code her, dann ich besser gucken, ob ich da was finden kann
 
Code:
<ImageView id="@+id/Suche_ImageView_logo_ID"
            android:layout_marginTop="10px"
            android:layout_width="180px"
            android:layout_height="67px"
            android:src="@drawable/logo"
            android:gravity="center_horizontal"

        />


so sieht mein code aus, aber leider geht es nicht, also das bild ist nicht in der Mitte!
 
ich denke, das liegt eher daran, dass du darum noch ein layout brauchst

also sowas

<LinearLayout
width= fill parent
height fill parent
>
<imageview

</linearlayout>

und dann gravity setzen
 
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/Suche_Tab"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff">
        
        <ImageView id="@+id/Suche_ImageView_logo_ID"
            android:layout_marginTop="10px"
            android:layout_width="180px"
            android:layout_height="67px"
            android:src="@drawable/logo"
            android:gravity="center_horizontal"

        />
        <EditText android:text="" 
            android:layout_marginTop="10px"
            android:id="@+id/Suche_EditText_Suchfeld_ID" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content">
        </EditText>
        <TextView android:id="@+id/Suche_TextView_Beispiel_ID"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/Suche_TextView_Beispiel"
            android:textColor="#000000"        
        />
        <Button android:id="@+id/Suche_Button_Suchen_ID" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Suche_Button_Suchen"
            android:layout_marginLeft="240px"
        />
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" > 
            
            <Button android:id="@+id/Suchen_Button_vonButton_ID"
                android:layout_marginTop="10px"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Suchen_Button_vonButton" />
                
            <TextView android:id="@+id/Suchen_TextView_vonText_ID"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#000000"    
               />
            </LinearLayout>
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
                
           <Button android:id="@+id/Suchen_Button_bisButton_ID"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Suchen_Button_bisButton" />
                
            <TextView android:id="@+id/Suchen_TextView_bisText_ID"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#000000"    
               />                                     
        </LinearLayout>
        <TextView android:id="@+id/Suchen_TextView_MaximalerPreis_ID"
                android:layout_marginTop="10px"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Suchen_TextView_MaximalerPreis"
                android:textColor="#000000"    
        />
        <EditText android:text="" 
            android:layout_marginTop="10px"
            android:id="@+id/Suche_EditTex_MaximalerPreis_ID" 
            android:layout_width="100px" 
            android:layout_height="wrap_content"
            android:textColor="#000000"    >
        </EditText>
        

</LinearLayout>

hier ist noch mal mein ganzer Code, denn eigentlich habe ich ja ein Layout drum, oder meinst du etwas anderes?
 
hab den fehler!

es muss heißen

android:layout_gravity="center_horizontal"
 
ok super ;) stimmt layout_gravity ;)

gut hast ja jetzt gefunden
 
Jetzt habe ich es ganz! Danke noch mal für deine schnell Hilfe!
bei TextView heiß es nur android:gravity="center_horizontal"
bei ImageView heiß es aber android:layout_gravity="center_horizontal"
 

Ähnliche Themen

AnnaBauer21
Antworten
6
Aufrufe
335
AnnaBauer21
AnnaBauer21
S
Antworten
7
Aufrufe
344
Silvasurf
S
koje71
Antworten
0
Aufrufe
215
koje71
koje71
Zurück
Oben Unten