2017-01-11 3 views
0

Ich bin neu im Design von Android, also möchte ich meine Hauptbildschirm Bilder für alle Geräte passen Ich möchte diese MainScreen-Seite in allen Geräten passen. Es hat 3 Bilder, die ich Gewicht gegeben habe, aber nichts scheint zu funktionieren, wenn ich es auf der Registerkarte teste. Es ist nicht die Art und Weise der Suche ich will, hier ist das BildWie kann ich meine XML-Bilder für alle Geräte anpassen?

enter image description here

hier ist mein XML .Ich weiß, ich soll für die Höhe nicht dp geben, aber wie es so aussehen zu lassen, ohne Größen zu geben.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    tools:context="com.example.zeba.broccoli.MainActivity" > 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" 
     android:layout_marginTop="50dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentStart="true"> 

     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 

      android:weightSum="1"> 

      <ImageView 
       android:id="@+id/ms1" 
       android:layout_width="match_parent" 
       android:layout_height="374dp" 
       android:layout_weight="7" 
       android:scaleType="fitXY" 
       android:src="@drawable/avatar" /> 


     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      > 


      <ImageView 
       android:id="@+id/ms2" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="fitXY" 

       android:src="@drawable/ee" 

       android:layout_weight=".5" /> 

      <ImageView 
       android:id="@+id/ms3" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="fitXY" 
       android:src="@drawable/dd" 
       android:layout_weight=".5" /> 
     </LinearLayout> 
    </LinearLayout> 


</RelativeLayout> 
+0

Feste Abmessungen für Bilder können mit Geräten variieren werden. Verwenden Sie _wrap_content_ für Bemaßungen und weisen Sie Ihren Designer an, Bilder nach verschiedenen Bildschirmauflösungen zu gestalten. – Piyush

+0

Wenn Sie keine Größen angeben möchten, müssen Sie Bilder unterschiedlicher Größe in separaten, ausklappbaren Ordnern speichern, z. B. drawable-xhdpi, drawable-xxhdpi usw. –

+0

, wenn ich das Bild nach Geräten wie hdpi, xxhdpi..like dass..dann kann es passen? –

Antwort

1

Mit diesem Code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="0.7"> 

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


      </LinearLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="0.3"> 


       <ImageView 
        android:id="@+id/ms2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight=".5" 
        android:scaleType="fitXY" 
        android:src="@mipmap/ic_launcher" /> 

       <ImageView 
        android:id="@+id/ms3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight=".5" 
        android:scaleType="fitXY" 
        android:src="@mipmap/ic_launcher" /> 

      </LinearLayout> 
     </LinearLayout> 
    </RelativeLayout> 

Hope this helfen Ihnen

+0

ok lass mich versuchen Sie .. –

+0

Ich habe Ihre Bildressource mit ic_launcher.so ersetzt, die entsprechend Ihrem Bedarf gesetzt wird. Vielen Dank. –

+0

thx buddy..it funktioniert –

1

folgende XML-Lösung finden Sie zu bekommen, was Sie brauchen.

Sie können die relative Breite und Höhe der einzelnen Ansichtselemente jederzeit ändern, indem Sie den Parameter layout_weight wiedergeben. Es ist wie geben Breite/Höhe in Prozenten:

<?xml version="1.0" encoding="utf-8"?> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:src="@android:drawable/btn_default" 
    android:scaleType="fitXY" 
    android:layout_weight="70"/> 

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

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:src="@android:drawable/btn_default" 
     android:scaleType="fitXY" 
     android:layout_weight="1"/> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:src="@android:drawable/btn_default" 
     android:scaleType="fitXY" 
     android:layout_weight="1"/> 
</LinearLayout> 

+0

thx..aber ich habe schon die Antwort –

Verwandte Themen