我的应用程序中有一个导航抽屉活动,我有一些片段。在一个片段中,我有一个Scrollview,里面有我的单选按钮组。单选按钮是从数据库中获取的数据动态添加的。问题是scrollview隐藏了应用程序顶部的2个单选按钮 这是xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nimesha.delivery.Curjob_fragment">
<Button
android:id="@+id/naviBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Navigate"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp"
android:layout_marginBottom="18dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:id="@+id/signoutbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="52dp"
android:layout_marginStart="52dp"
android:text="Button"
android:layout_below="@+id/scrollView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/naviBtn"
android:layout_marginTop="@dimen/nav_header_vertical_spacing"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:clipToPadding="true"
android:fillViewport="true"
android:layout_weight="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioGroup
android:id="@+id/radioGrp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
这就是我填充单选按钮组的方式
for (DataSnapshot jobSnap: dataSnapshot.getChildren()) {
String key = jobSnap.getKey();
Double lat = jobSnap.child("lat").getValue(Double.TYPE);
Double longi =jobSnap.child("long").getValue(Double.TYPE);
Log.d(TAG, key + " " + lat + " " + longi);
RadioButton radioButton = new RadioButton(getActivity());
radioButton.setLayoutParams
(new RadioGroup.LayoutParams
(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT));
radioButton.setText("Radio Button #" + lat);
radioButton.setId(count);
//add it to the group.
radiogroup.addView(radioButton, count);
count += 1 ;
}
https://i.stack.imgur.com/26Qfj.jpg
顶部应该有一些单选按钮
答案 0 :(得分:1)
尝试以下代码
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/naviBtn"
android:layout_marginTop="@dimen/nav_header_vertical_spacing"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:fillViewport="true"
android:background="@color/colorPrimaryDark">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioGroup
android:id="@+id/radioGrp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</ScrollView>
<Button
android:id="@id/naviBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Navigate"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp"
android:layout_marginBottom="18dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:id="@+id/signoutbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="52dp"
android:layout_marginStart="52dp"
android:text="Button"
android:layout_below="@+id/scrollView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>