主要 Activity 中有两个 LinearLayouts 页眉和页脚
还有在它们之间的 swipeRefreshLayout 里面的 RecyclerView
现在我想使用 LayoutParam 隐藏页眉和页脚,但在更改 layoutParam 和 swipeRefreshLayout 的高度没有改变后显示间隙。
如何解决?
最佳答案
我已经尝试使用演示来解决您的问题。
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);
}
}
当我点击顶部 View 时。底部较小,没有缝隙。也许它可以帮助你。
关于android - 如何在android中滚动时隐藏页眉和页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33979665/