相关疑难解决方法(0)

Android:为什么视图没有maxHeight?

View有一个minHeight但不知何故缺少一个maxHeight:

我想要实现的是让一些项目(视图)填满ScrollView.当有1..3项时,我想直接显示它们.意味着它ScrollView具有1,2或3个项目的高度.

当有4个或更多项目我希望ScrollView停止扩展(因此a maxHeight)并开始提供滚动.

但是,遗憾的是没有办法设置maxHeight.因此,我可能必须以ScrollView编程方式WRAP_CONTENT将高度设置为有1..3项3*sizeOf(View)时的高度,并将高度设置为有4个或更多项时的高度.

任何人都可以解释为什么没有maxHeight提供,什么时候已经有minHeight

(顺便说一下:有些观点,比如ImageView已经maxHeight实施了.)

layout android view autoresize

168
推荐指数
7
解决办法
11万
查看次数

如何以编程方式调整自定义视图的大小?

我正在编写一个自定义视图,从RelativeLayout扩展,我想以编程方式调整它,我该怎么办?

自定义视图类是这样的:

public ActiveSlideView(Context context, AttributeSet attr){
        super(context, attr);
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if(inflater != null){       
            inflater.inflate(R.layout.active_slide, this);
        }
Run Code Online (Sandbox Code Playgroud)

android resize

158
推荐指数
9
解决办法
23万
查看次数

如何设置RecyclerView Max Height

我想设置RecylerView的Max Height.我可以使用下面的代码设置最大高度.下面的代码使高度为当前屏幕的60%.

     DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int a = (displaymetrics.heightPixels * 60) / 100;
    recyclerview1.getLayoutParams().height = a;
Run Code Online (Sandbox Code Playgroud)

但现在的问题是,如果它没有项目,那么它的高度也是60%.所以我想在没有项目时将其高度设置为0.

我希望实现类似的东西.

    if(recyclerview's height > maxHeight)
then set recyclerview's height to maxHeight
    else dont change the height of recyclerview.
Run Code Online (Sandbox Code Playgroud)

我怎么设置它?请帮助我,我坚持下去

android android-recyclerview

21
推荐指数
5
解决办法
2万
查看次数

如何设置RecyclerView的最大高度?

我必须implementinga RecylerView,它应该包含内容,如果它只包含项目内容高度较少.如果项目的增加喜欢250dp,它应该设置为max heght(250dp)并且能够滚动.如何实现这个Relative layout.我的父布局是一个.

这是我的布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

屏幕截图,如果它只有一个项目.这应该是wrap_content.

屏幕截图,如果它只有一个项目.这应该是wrap_content.

android relativelayout android-layout android-studio

2
推荐指数
1
解决办法
6397
查看次数