2016-08-19 3 views
1

ich ein Bild von einem Socket-Server mit diesem:Android Fit Bild in Image

byte[] decodedString = Base64.decode(values[26], Base64.NO_WRAP); 
    master_bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); 
    master_frame.setImageBitmap(master_bitmap); 

Xml

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

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Large Text" 
    android:id="@+id/textView2" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginLeft="27dp" 
    android:layout_marginStart="27dp" 
    android:layout_marginTop="39dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Large Text" 
    android:id="@+id/textView4" 
    android:layout_alignTop="@+id/textView2" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:layout_marginRight="50dp" 
    android:layout_marginEnd="50dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Large Text" 
    android:id="@+id/textView6" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="196dp" /> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/iv_master" 
    android:layout_below="@+id/textView2" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_toStartOf="@+id/textView6" 
    android:layout_above="@+id/textView6" 
    android:layout_toLeftOf="@+id/textView6" /> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/iv_slave" 
    android:layout_above="@+id/textView6" 
    android:layout_toRightOf="@+id/textView6" 
    android:layout_alignTop="@+id/iv_master" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:scaleType="centerInside" 
    android:adjustViewBounds="true"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Text" 
    android:id="@+id/textView8" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:textSize="12dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Text" 
    android:id="@+id/textView9" 
    android:layout_alignBottom="@+id/textView8" 
    android:layout_toRightOf="@+id/textView8" 
    android:layout_toEndOf="@+id/textView8" 
    android:textSize="12dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Text" 
    android:id="@+id/textView14" 
    android:layout_alignBottom="@+id/textView9" 
    android:layout_toRightOf="@+id/textView9" 
    android:layout_toEndOf="@+id/textView9" 
    android:textSize="12dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Text" 
    android:id="@+id/textView22" 
    android:layout_alignBottom="@+id/textView14" 
    android:layout_toRightOf="@+id/textView14" 
    android:layout_toEndOf="@+id/textView14" 
    android:textSize="12dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Text" 
    android:id="@+id/textView23" 
    android:layout_alignBottom="@+id/textView22" 
    android:layout_toRightOf="@+id/textView22" 
    android:layout_toEndOf="@+id/textView22" 
    android:textSize="12dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Text" 
    android:id="@+id/textView24" 
    android:layout_alignParentBottom="true" 
    android:layout_toRightOf="@+id/textView23" 
    android:layout_toEndOf="@+id/textView23" 
    android:textSize="12dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Text" 
    android:id="@+id/textView25" 
    android:layout_alignParentBottom="true" 
    android:layout_toRightOf="@+id/textView6" 
    android:layout_toEndOf="@+id/textView6" 
    android:textSize="12dp" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Text" 
    android:id="@+id/textView26" 
    android:layout_alignBottom="@+id/textView25" 
    android:layout_toRightOf="@+id/textView25" 
    android:layout_toEndOf="@+id/textView25" 
    android:textSize="12dp" /> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/iv_arena" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:layout_above="@+id/textView14" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

Ich möchte die passen Bild auf (Layout):

Layout

Aber es zeigt wie folgt aus:

ich alle Bitmaps richtig in den ImageViews passen wollen. Es kann gedehnt werden.

PS: Es ist auch sehr schwierig, ein Layout zu erstellen ... Warum kann ich die Bildansichten nicht nahe beieinander platzieren?

Screenshot von meinem Android ScreenShot of My Android

der Faust zwei Bilder sind 640x360 und die letzte 1159x398

Antwort

1

Wenn Sie ein Bild von diesem Seitenverhältnis wollen in diesem Image passen, android:scaleType="centerCrop" in seiner XML-Attribute verwenden.

0
android:scaleType="fitxy" in xml 

Dies wird Ihre gesamte Imageview füllen.

0

Schritt 1: Abrufen der Geräteanzeige Breite & Höhe dynamisch mit.

DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics); 

int height = metrics.heightPixels; 
int width = metrics.widthPixels; 

Schritt 2: Layout-Parameter auf die Bildansicht

imagePhoto.setLayoutParams(getLayout(5, 5, height/2, width/2)); 




private FrameLayout.LayoutParams getLayout(int fMarginLeft, int fMarginTop, int fWidth, int fHeight) { 
     FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
     params.setMargins(fMarginLeft, fMarginTop, 0, 0); 
     params.width = fWidth; 
     params.height = fHeight; 
     return params; 
    }