首页 > 解决方案 > 由于重量android studio,Scrollview不滚动

问题描述

所以我在我的 GUI 中添加了 weightsum 和 weight,现在它不再滚动了。在我增加重量之前它起作用了。我已经在网上研究过是否有解决方案,但我无法在任何地方找到信息

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:paddingTop="20dp"
        android:background="#2aa5a5"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/scrollView"
        android:fillViewport="true">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/inside_linear"
            android:weightSum="120">
        </LinearLayout>
     </ScrollView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:background="#0000FF"
        android:gravity="center">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#D3D3D3"
            android:text="Sorteer op"
            android:id="@+id/sorteer_button"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/maps_button"
            android:background="#D3D3D3"
            android:layout_marginLeft="45dp"
            android:text="Google Maps"
            />
    </LinearLayout>
 </RelativeLayout>

这是我将按钮和文本视图添加到内部线性布局的动态代码。

for(int i = 0; i < dummyNames.length;i++){
            LinearLayout linear = new LinearLayout(this);
            LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,0);
            linearLayoutParams.weight = 20;
            linear.setOrientation(LinearLayout.HORIZONTAL);
            linear.setPadding(10,0,0,0);
            linear.setLayoutParams(linearLayoutParams);
            TextView restName = new TextView(this);
            restName.setText(dummyNames[i]);
            restName.setTextSize(18);
            Button menuButton = new Button(this);
            LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(167,100);
            buttonLayoutParams.setMargins(30,0,0,0);
            menuButton.setLayoutParams(buttonLayoutParams);
            menuButton.setId(i);
            menuButton.setText("menu");
            menuButton.setTextSize(13);
            menuButton.setBackgroundResource(R.drawable.roundedbutton);
            Button infoButton = new Button(this);
            LinearLayout.LayoutParams infoLayoutParams = new LinearLayout.LayoutParams(167,100);
            infoLayoutParams.setMargins(30,0,0,0);
            infoButton.setLayoutParams(infoLayoutParams);
            infoButton.setId(i);
            infoButton.setText("info");
            infoButton.setTextSize(13);
            infoButton.setBackgroundResource(R.drawable.roundedbutton);
            Button locatieButton = new Button(this);
            LinearLayout.LayoutParams locatieLayoutParams = new LinearLayout.LayoutParams(167,100);
            locatieLayoutParams.setMargins(30,0,0,0);
            locatieButton.setLayoutParams(locatieLayoutParams);
            locatieButton.setId(i);
            locatieButton.setText("locatie");
            locatieButton.setTextSize(13);
            locatieButton.setBackgroundResource(R.drawable.roundedbutton);
            Button websiteButton = new Button(this);
            LinearLayout.LayoutParams websiteLayoutParams = new LinearLayout.LayoutParams(167,100);
            websiteLayoutParams.setMargins(30,0,0,0);
            websiteButton.setLayoutParams(websiteLayoutParams);
            websiteButton.setId(i);
            websiteButton.setText("website");
            websiteButton.setTextSize(13);
            websiteButton.setBackgroundResource(R.drawable.roundedbutton);

            linear.addView(restName);
            linear.addView(menuButton);
            linear.addView(infoButton);
            linear.addView(locatieButton);
            linear.addView(websiteButton);
           mInsideLinear.addView(linear);

标签: androidandroid-studio

解决方案


推荐阅读