2017-06-05 64 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

仍然没有运气。没有工作。 –

相关问题