滚动视图不会滚动,因为重量的Android Studio

时间:2018-10-23 14:20:10

标签: android android-studio

所以我在我的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>

这是动态代码,在其中我将按钮和textview添加到内部linearlayout中。

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);

0 个答案:

没有答案