Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为android的布局组件添加灵活的大小调整_Android_Android Layout_Android Recyclerview - Fatal编程技术网

如何为android的布局组件添加灵活的大小调整

如何为android的布局组件添加灵活的大小调整,android,android-layout,android-recyclerview,Android,Android Layout,Android Recyclerview,有没有办法在android布局的XML中添加灵活的大小调整属性。 我想添加元素,使一个元素的高度/宽度等于父元素的高度减去另一个元素 与CSS一样,我们可以使用calc()函数 例如:计算(100%-100px) 在android中有没有类似的方法,比如: 我设定 android:layout_height="?attr/actionBarSize" 那么,是否有类似的情况: <RecyclerView android:layout_height = "(match_parent

有没有办法在android布局的XML中添加灵活的大小调整属性。 我想添加元素,使一个元素的高度/宽度等于父元素的高度减去另一个元素

与CSS一样,我们可以使用
calc()
函数 例如:计算(100%-100px)

在android中有没有类似的方法,比如:

我设定

android:layout_height="?attr/actionBarSize"
那么,是否有类似的情况:

<RecyclerView 
  android:layout_height = "(match_parent - ?attr/actionBarSize)"/>


有没有办法在XML本身中实现这一点,而不是在活动中使用java?

没有。但是你可以通过使用边距来实现

例如,如果您需要从底部“切割”相对物的高度,您可以使用:

android:layout_marginBottom="?android:attr/actionBarSize"
或者,如果您想从头开始:

android:layout_marginTop="?android:attr/actionBarSize"

是的,您可以在相对布局中这样做,如下所示

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/button" />

</RelativeLayout>

在上面的代码中,我首先将按钮放在底部。现在,对于剩余的位置,我想显示listview。所以我把listview放在按钮上方,使其与父项匹配,这样它将保留所有剩余空间