2016-08-28 2 views
1
passend

ich einen Scroll haben, dass die Ausgabe wie folgt aussieht:-Layout innerhalb Scroll nicht die Bildschirmgröße richtig

The layout that I have

Dies ist der Code, den ich dafür verwenden:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/mainContainer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/first_grey" 
    tools:ignore="ContentDescription" > 

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

     <LinearLayout android:id="@+id/homeHeader" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/first_grey" 
      tools:ignore="ContentDescription" 
      android:orientation="vertical"> 

      <RelativeLayout android:id="@+id/imageLogo" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 

       <ImageView android:id="@+id/imgBackgroundHomeGuest" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:adjustViewBounds="true" 
        android:scaleType="centerCrop" 
        android:src="@drawable/diversity" /> 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@drawable/background_home_view" 
        android:layout_marginTop="10dp" 
        android:layout_alignParentBottom="true"> 

        <LinearLayout android:id="@+id/contentSpinnerCity" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginEnd="20dp" 
         android:layout_marginLeft="20dp" 
         android:layout_marginRight="20dp" 
         android:layout_marginStart="20dp" 
         android:layout_marginTop="15dp" 
         android:orientation="horizontal"         android:background="@drawable/box_corners_round_white"> 

         <Spinner android:id="@+id/spinnerCity" 
          android:layout_width="match_parent" 
          android:layout_height="45dp" 
          android:paddingLeft="16dp" 
          android:paddingStart="16dp" 
          android:paddingRight="16dp" 
          android:paddingEnd="16dp" 
          android:layout_marginEnd="10dp" 
          android:layout_marginRight="10dp" 
           android:gravity="center_vertical|center_horizontal" 
          android:layout_gravity="center_vertical|center_horizontal" > 

         </Spinner> 

        </LinearLayout> 

        <LinearLayout android:id="@+id/contentSpinnerCategory" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginEnd="20dp" 
         android:layout_marginLeft="20dp" 
         android:layout_marginRight="20dp" 
         android:layout_marginStart="20dp" 
         android:layout_marginTop="15dp" 
         android:orientation="vertical" 
         android:background="@drawable/box_corners_round_white" 
         android:layout_below="@+id/contentSpinnerCity" > 

         <Spinner android:id="@+id/spinnerCategory" 
          android:layout_width="match_parent" 
          android:layout_height="45dp" 
          android:paddingLeft="16dp" 
          android:paddingStart="16dp" 
          android:paddingRight="16dp" 
          android:paddingEnd="16dp" 
          android:layout_marginEnd="10dp" 
          android:layout_marginRight="10dp" 
          android:gravity="center_vertical|center_horizontal" 
          android:layout_gravity="center_vertical|center_horizontal" > 

         </Spinner> 

        </LinearLayout> 

        <LinearLayout android:id="@+id/btnNearMeHome" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/contentSpinnerCategory" 
         android:layout_marginEnd="20dp" 
         android:layout_marginLeft="20dp" 
         android:layout_marginRight="20dp" 
         android:layout_marginStart="20dp" 
         android:layout_marginTop="15dp" 
         android:layout_marginBottom="15dp" 
         android:gravity="center" 
         android:clickable="true" 
         android:background="@drawable/box_corners_round_red" > 

         <ImageView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:adjustViewBounds="true" 
          android:scaleType="fitCenter" 
          android:src="@drawable/ic_action_search_white" /> 

         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/search" /> 

        </LinearLayout> 

       </RelativeLayout> 

      </RelativeLayout> 

      <LinearLayout android:id="@+id/homeBottom" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginEnd="50dp" 
       android:layout_marginLeft="16dp" 
       android:layout_marginRight="50dp" 
       android:layout_marginStart="16dp" 
       android:orientation="vertical"> 

       <TextView android:id="@+id/txtWelcomeHome" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="15dp" 
        android:textColor="@color/fourth_grey" 
        android:textStyle="bold" 
        android:textSize="30sp" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:gravity="center_vertical" 
        android:text="@string/guest.home.welcome_text" 
        android:textColor="@color/fourth_grey" 
        android:textSize="20sp" /> 

       <TextView android:id="@+id/btnArrowDown" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="5dp" 
        android:layout_marginBottom="8dp" 
        android:text="@string/fa_sort_desc" 
        android:textColor="@color/red" 
        android:textSize="28sp" 
        android:gravity="center|center_vertical" /> 

      </LinearLayout> 

     </LinearLayout> 

     <LinearLayout android:id="@+id/homeFooter" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <TextView android:id="@+id/becomeAHostHeader" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="30dp" 
       android:gravity="center_horizontal" 
       android:textColor="@color/fourth_grey" 
       android:textStyle="bold" 
       android:textAllCaps="true" 
       android:textSize="20sp" 
       android:text="@string/guest.home.BecomeAHost.header"/> 

      <TextView android:id="@+id/becomeAHostDescription" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="30dp" 
       android:gravity="center_horizontal" 
       android:textColor="@color/fourth_grey" 
       android:textSize="18sp" 
       android:text="@string/guest.home.BecomeAHost.description"/> 

      <Button android:id="@+id/btnBecomeAHost" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="30dp" 
       android:background="@drawable/box_corners_round_red" 
       android:text="@string/menu.become_a_host" 
       android:textSize="16sp" /> 

     </LinearLayout> 

    </LinearLayout> 

</ScrollView> 

Ich möchte um das Layout homeHeader auf den Gerätebildschirm anzupassen.

Ich habe versucht, die aktuelle Bildschirmgröße bekommen und legen Sie dann seine Höhe auf das Layout wie folgt aus:

Display display = getWindowManager().getDefaultDisplay(); 
Point size = new Point(); 
display.getSize(size); 
int height = size.y; 

final LinearLayout linearLeft = (LinearLayout) findViewById(R.id.homeHeader); 
LayoutParams params = linearLeft .getLayoutParams(); 
// Changes the height and width to the specified *pixels* 
params.height = height; 

Allerdings, wenn ich es laufen, sieht meine Ausgabe wie folgt:

The screen output in the emulator

Tyvm für jede Hilfe!

+0

Wie groß ist das Bild? Ich kann mir einfach vorstellen, dass du das Bild nicht auf den Bildschirm dehnst. –

+0

Es ist 959 x 1280. Ich habe wrap_content für seine Höhe verwendet, denn wenn ich eine bestimmte Größe verwenden würde, wäre das Bild beschädigt –

Antwort

0

Ich löste mit android:weightSum="1" für das Layout und dann für seine Kinder layout_weight tat die Arbeit, die ich für die Einstellung der Größe für jedes Layout wollte.

0

Warum stellen Sie seine Höhe und die Bildansichten nicht auf ein? Lassen Sie uns wissen, ob es funktioniert, bitte. Prost :)

+0

Die Bildansicht kann nicht übergeordnet sein, weil das erste Layout zu dem Symbol neben dem Ausdruck "Start discovery tolle Dinge zu tun " –

Verwandte Themen