2017-07-31 133 views
0

我在我的應用程序中有一個導航抽屜活動,我在那裏有一些片段。在一個片段中,我有一個滾動視圖,裏面有我單選按鈕組。單選按鈕是從數據庫獲取的數據中動態添加的。問題是滾動視圖是在應用 此的頂部隱藏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

它們是隱藏的還是未添加到組中? –

+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> 
+0

藍色背景隱藏了問題,但同時它隱藏了我的活動標題欄,所以這不是我正在尋找的 –

+1

那個背景不是故意的,只是爲了測試目的而已 – Rahul

+0

找出問題所在。使用線性佈局。現在看起來像我期望的那樣。謝謝 –