2017-09-13 42 views
0

我将自定义视图设置为底部,并且最初它的父级高度为200dp。当我点击自定义视图时,我必须将父级设置为匹配父级。以后我会在全屏幕上动画定制视图。如何在更改父级高度后在底部保留自定义视图

发生的事情是,当我设置相对布局(父视图)的大小以编程方式匹配父项时,它的子视图也会向上移动。我怎么能过来呢?

下面是布局定义:

<RelativeLayout 
    android:id="@+id/rlTreatmentDone" 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:layout_alignParentBottom="true" 
    android:clickable="false" 
    android:gravity="bottom"> 


    <com.firsttreatmentflow.doneTreatment.DoneControllerView 
     android:id="@+id/doneViewController" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:minHeight="200dp"></com.firsttreatmentflow.doneTreatment.DoneControllerView> 


    <LinearLayout 
     android:id="@+id/llArrowText" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/ivUpArrow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/tvDone" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="10dp" 
      android:clickable="true" 
      android:src="@drawable/arrow_up" 
      android:visibility="gone" /> 

     <TextView 

      android:id="@+id/tvDone" 
      style="@style/BodyBoldTextStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/bottomReferenceView" 
      android:layout_centerHorizontal="true" 
      android:clickable="true" 
      android:text="Done" 
      android:textColor="@color/uikit_white" 
      android:visibility="gone" /> 
    </LinearLayout> 
现在

自定义视图的点击,我改变布局高度如下

llArrowText.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 



      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
      params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
      rlTreatmentDone.setLayoutParams(params); 



      doneViewController.setStartControllerClicked(true); 
     } 
    }); 

这将移动自定义视图如下 enter image description here

回答

0

在你的代码中,你已经将LayoutParams Height设置为WRAP_CONTENT而不是MATCH_PARENT,我猜你就是你实际上打算做什么?这会使"@+id/rlTreatmentDone"变小并将其向上移动。

+0

不,它不工作通过改变匹配父,我想保持自定义视图底部 – chethan

相关问题