android - 由于重量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);
解决方案
推荐阅读
- c# - 提交后需要进行部分重新加载,以便用户不需要“刷新”或“F5”
- python - 20种不同类型消息的朴素贝叶斯分类只能预测三种不同类型的消息
- c - 在 C 中使用线程实现管道
- javascript - JQuery: stop synchronizing inputs
- vb.net - 如何处理异常(命令执行过程中遇到致命错误)
- angular - 如何在 Angular 7 中使用身份验证令牌获取 rest api 的数据?
- jsx - componentDidMount 没有被调用
- r - 增加表格大小并在行和列之间添加行(类似于 Excel)
- sql - SQL 从两个表中选择排除
- c - 2Darray 中的 2nd label [1st][2nd] 是什么意思,例如 .char label[11][6]