2015-11-29 57 views
1

在兩個LinearLayouts頁眉和頁腳中的主要活動如何隱藏滾動頁眉和頁腳中的Android

也RecyclerView內swipeRefreshLayout它們之間

現在我想隱藏頁眉和頁腳使用LayoutParam,但它顯示更改layoutParam後的差距,swipeRefreshLayout的高度不會更改。

如何解決?

回答

1

我試圖解決您的問題使用演示。

XML文件

<?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="#fff" 
    android:orientation="vertical"> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:onClick="click" 
     android:background="#fffe4a" /> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:layout_marginTop="2dp" 
     android:background="#3489ff" /> 

    <View 
     android:id="@+id/view_bottom" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:background="#fffe4a" /> 

</LinearLayout> 

java文件。

package com.example.wangze.instantdemo1; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.LinearLayout; 


public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

    public void click(View view){ 
     View view_bottom = findViewById(R.id.view_bottom); 
     LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view_bottom.getLayoutParams(); 
     layoutParams.height = 20; 
     view_bottom.setLayoutParams(layoutParams); 
    } 
} 

當我點擊頂視圖。底部較小,沒有間隙。也許它可以幫助你。

相關問題