1

因此,我有一個ImageView裏面的FrameLayout。我需要這樣。我覺得這裏的問題是圖像,它的大小本身。圖像的佈局將屏幕上的所有其他視圖向下推進,留下應該來自佈局的相當大的空白空間。佈局按下屏幕

我發現硬編碼的高度值讓我最小化這個問題。如果高度是wrap_content,圖像將達到同一點,但應該從佈局中獲得的空白空間會延伸到極長的長度。

所以我想知道這是一個圖像大小(或分辨率?)問題(似乎是)或其他任何東西,並且如果有比硬編碼佈局高度更好的解決方案。提前致謝。

下面是代碼:

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

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="700dp"> 

     <ImageView 
      android:id="@+id/image_header" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scaleType="fitStart" 
      android:src="@drawable/me_and_gundam" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/gradient" /> 
    </FrameLayout> 


    <TextView 
     android:fitsSystemWindows="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:text="My Nanodegree Apps!" 
     android:textAlignment="center" 
     android:textSize="24sp" /> 

,這裏是什麼樣子:

enter image description here

回答

2

有你試圖把框架佈局高度WRAP_CONTENT它的工作對我罰款

<ImageView 
     android:id="@+id/image_header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scaleType="fitStart" 
     android:src="@drawable/me_and_gundam" /> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/gradient" /> 
</FrameLayout> 
+0

不,它不起作用。 – Karnkuret