2017-06-05 56 views
0

我有一個imageview &相對佈局,其中包含兩個按鈕的佈局應該與底部對齊,並且圓形圖像應伸展以佔用剩餘空間。我嘗試了其他答案,但無法做到這一點。我有下面的代碼和圖像。如何將特定佈局對齊到底部並修復imageview的大小以覆蓋剩餘空間?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/cardview_light_background" 
android:clickable="true"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <include layout="@layout/toolbar_child_with_progress" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/toolbar_child"/> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/toolbar_child"> 
     <RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      > 
       <ImageView 
        android:id="@+id/iv_SavedInvoice" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:src="@drawable/service_app_logo" 
        android:scaleType="fitStart" 
        android:adjustViewBounds="true" 
        android:layout_centerHorizontal="true" 
        /> 

       <LinearLayout 
        android:id="@+id/ll_inner" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:layout_below="@+id/iv_SavedInvoice" 
        android:layout_alignParentBottom="true" 
        > 
        <Button 
         style="@style/PrimaryButton" 
         android:layout_marginTop="20dp" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/form_proof_replace_invoice" 
         android:id="@+id/button_ReplaceInvoice" /> 
        <Button 
         style="@style/NoBorderButton" 
         android:layout_marginTop="20dp" 
         android:layout_marginBottom="20dp" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/form_proof_next" 
         android:id="@+id/button_SavedProofNext" /> 
       </LinearLayout> 
      </RelativeLayout> 
    </ScrollView> 
</RelativeLayout> 

Align_Parent_Bottom

回答

1

我不知道你爲什麼使用ScrollView和其他嵌套佈局。您想要的UI可以通過使用佈局權重屬性來簡單地實現。您檢查此代碼並根據您的需要進行更改。'

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/cardview_light_background" 
android:clickable="true" 
android:orientation="vertical"> 

<include 
    android:id="@+id/toolbar_child" 
    layout="@layout/toolbar_child_with_progress" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"> 

    <ImageView 
     android:id="@+id/iv_SavedInvoice" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true" 
     android:adjustViewBounds="true" 
     android:scaleType="fitStart" 
     android:src="@mipmap/ic_launcher" /> 


</RelativeLayout> 

<LinearLayout 
    android:id="@+id/ll_inner" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_below="@+id/iv_SavedInvoice" 
    android:orientation="vertical"> 

    <Button 
     android:id="@+id/button_ReplaceInvoice" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:text="form_proof_replace_invoice" /> 

    <Button 
     android:id="@+id/button_SavedProofNext" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:text="form_proof_next" /> 
</LinearLayout> 

</LinearLayout> 
+0

謝謝,scrollview是罪魁禍首。其實我有一些其他的代碼,我沒有發佈。我在scrollview之上移動了佈局,並且它正在工作。 –

+0

你能否幫我一個小忙。我已經使用「fitXY」來適應圖像的高度以覆蓋按鈕上的高度間隙。如何保持橫向圖像的縱橫比並將圖像的寬度發送出屏幕? –

+0

與centerCrop重新鑲嵌xY。它將保持長寬比。但它會使一些地區crop。。如果它很好,試試這個。或者可以嘗試一些ImageView的庫。 –

0

您應該設置layout_heightmatch_parent代替WRAP_CONTENT的。

<LinearLayout 
        android:id="@+id/ll_inner" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical" 
        android:layout_below="@+id/iv_SavedInvoice" 
        android:layout_alignParentBottom="true" 
        > 

其次,在你的滾動型部分添加android:fillViewport="true"

+0

這將擴大包含按鈕的linearlayout的高度。我希望ll_inner的高度是靜態的。我希望圖像的高度/寬度在這裏是動態的。我嘗試過,並沒有工作。 –

+0

@BinodLama在ScrollView中添加'android:fillViewport =「true」部分 –

+0

仍然沒有運氣。沒有工作。 –

相關問題