Java 如果要将ListView与多个ImageButtons一起使用(因此它可以滚动),我将如何使用代码调整按钮的大小?

Java 如果要将ListView与多个ImageButtons一起使用(因此它可以滚动),我将如何使用代码调整按钮的大小?,java,android,Java,Android,我想让按钮自动调整到屏幕大小,它工作得很好,但由于我需要一个ListView使其可滚动,它将不再工作,因为它抛出了一个异常 呈现期间引发异常:AdapterView中不支持addView(视图,LayoutParams) 这是我目前用来调整图像大小的代码(不确定是否有用): 这是XML: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingTop="16dp" x

我想让按钮自动调整到屏幕大小,它工作得很好,但由于我需要一个ListView使其可滚动,它将不再工作,因为它抛出了一个异常

呈现期间引发异常:AdapterView中不支持addView(视图,LayoutParams)

这是我目前用来调整图像大小的代码(不确定是否有用):

这是XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="16dp"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.eren.valour.FirstTimeLogin">


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="@string/getStarted"
    android:id="@+id/getStartedText"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
   />
<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   <ImageButton
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_marginTop="100dp"
       android:background="@drawable/facebook"
       android:id="@+id/facebookLogin"
       android:onClick="facebookLogin"

       />
   <ImageButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/instagram"
        android:layout_below="@+id/facebookLogin"
        android:id="@+id/instagramLogin"
        android:onClick="instagramLogin"
        />
    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/twitter"
        android:layout_below="@+id/instagramLogin"
        android:id="@+id/twitterLogin"
        android:onClick="twitterLogin"
        />

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/reddit"
        android:layout_below="@+id/twitterLogin"
        android:id="@+id/redditLogin"
        android:onClick="redditLogin"
        />
    </ListView>


您应该创建listview\u行,并用适配器(ArrayAdapter)填充listview。如果listview项很多,则listview可以滚动

listview_row.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/view_sign_up"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@android:color/white">

    <ImageButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/facebook"
        android:id="@+id/facebookLogin"
        android:onClick="facebookLogin" />

    <ImageButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/instagram"
        android:layout_below="@+id/facebookLogin"
        android:id="@+id/instagramLogin"
        android:onClick="instagramLogin" />

    <ImageButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/twitter"
        android:layout_below="@+id/instagramLogin"
        android:id="@+id/twitterLogin"
        android:onClick="twitterLogin" />

    <ImageButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/reddit"
        android:layout_below="@+id/twitterLogin"
        android:id="@+id/redditLogin"
        android:onClick="redditLogin" />
</LinearLayout>

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="16dp"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.eren.valour.FirstTimeLogin"
    android:orientation="vertical">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/getStarted"
        android:id="@+id/getStartedText"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>
</LinearLayout>


Listview或LinearLayout?我希望它可以滚动
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="16dp"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.eren.valour.FirstTimeLogin"
    android:orientation="vertical">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/getStarted"
        android:id="@+id/getStartedText"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>
</LinearLayout>