2017-03-24 44 views
0

动态增加和减少相对布局,当回收商查看从屏幕底部弹出时,我想缩小相对布局的大小,并在使用它之后屏幕将恢复到正常大小(在回收站查看im sung图标放在相对视图上)动态增加和减少相对布局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    android:layout_weight="1"> 

////////tool bar 
    <include layout="@layout/toolbar" /> 


    <RelativeLayout 
     android:id="@+id/rel1" 
     android:layout_width="wrap_content" 
     android:layout_height="400dp" 
     android:layout_below="@+id/toolbar" 
     android:layout_weight="1"> 

     <com.cmlibrary.CircleMenu 
      android:id="@+id/circle_menu" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="180dp" 
      android:layout_marginTop="180dp" 

      /> 
    </RelativeLayout> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:layout_below="@+id/rel1" 
     android:padding="5dp" /> 
    </RelativeLayout> 
+0

欢迎来到SO!请参阅[如何提出一个好问题?](https://stackoverflow.com/help/how-to-ask)和[如何创建一个最小,完整和可验证的示例](https:// stackoverflow.com/help/mcve)。 – Olaia

回答

0

更好的方法是根据需要显示和隐藏视图的可见性。但如果你想增加和减少大小,那么下面的代码将帮助你。

private void layoutParams() { 
    RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams(); 
    ViewGroup.LayoutParams params = recyclerView.getLayoutParams(); 
    /* When recyclerView shows*/ 
    layoutParams.height = layoutParams.height - params.height; 
    relativeLayout.setLayoutParams(layoutParams); 

    /* When recyclerView hidden*/ 
    layoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT; 
    relativeLayout.setLayoutParams(layoutParams); 
} 

希望这会有所帮助。

+0

如何显示在相对布局顶部的回收站视图,以及在使用回收站视图后如何隐藏,我在回收站视图上使用图标以及设置图标后如何隐藏该视图,感谢结果,它按照预期 – Abhinav