ExpandableView
声明:资源链接索引至第三方,平台不作任何存储,仅提供信息检索服务,若有版权问题,请https://help.coders100.com提交工单反馈
要实现这个功能,首先需要在布局文件中添加一个ExpandableViewExpandable控件,然后在对应的Activity中设置其属性。具体操作如下:
1. 在布局文件中添加一个ExpandableViewExpandable控件,例如:
2. 在对应的Activity中设置ExpandableViewExpandable的属性,例如:
这样,当展开时如果超过屏幕的高度时父控件会自动上移,滚动的父布局可以是RecyclerView或ScrollView。Expandable 动画列表展开收起 ,列表右边的指示箭头可以再任何位置 当展开时如果超过屏幕的高度时父控件自动上移,滚动的父布局可以是RecyclerView,ScrollView
1. 在布局文件中添加一个ExpandableViewExpandable控件,例如:
2. 在对应的Activity中设置ExpandableViewExpandable的属性,例如:
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
public class MainActivity extends AppCompatActivity {
private ExpandableViewExpandable expandableButton;
private RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
expandableButton = findViewById(R.id.expandable_button);
recyclerView = findViewById(R.id.recycler_view);
expandableButton.setOnExpandListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (recyclerView.getLayoutManager().getChildCount() > 0) {
int currentHeight = recyclerView.getHeight();
int maxHeight = getResources().getDisplayMetrics().heightPixels - currentHeight;
int newHeight = Math.min(maxHeight, currentHeight + expandableButton.getHeight());
recyclerView.scrollTo(0, newHeight);
}
}
});
}
}这样,当展开时如果超过屏幕的高度时父控件会自动上移,滚动的父布局可以是RecyclerView或ScrollView。Expandable 动画列表展开收起 ,列表右边的指示箭头可以再任何位置 当展开时如果超过屏幕的高度时父控件自动上移,滚动的父布局可以是RecyclerView,ScrollView
访问申明(访问视为同意此申明)
2.部分网络用户分享TXT文件内容为网盘地址有可能会失效(此类多为视频教程,如发生失效情况【联系客服】自助退回)
3.请多看看评论和内容介绍大数据情况下资源并不能保证每一条都是完美的资源
4.是否访问均为用户自主行为,本站只提供搜索服务不提供技术支持,感谢您的支持