2017-04-26 16 views
0
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    tools:context="mcb.myclickbazaar.Fragments.DateTimePlace"> 
<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:isScrollContainer="false" 
    android:fillViewport="true" 
    android:padding="10dp"> 

      <LinearLayout> 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

       <LinearLayout...> 

       <LinearLayout...> 

       <LinearLayout...> 

       <LinearLayout...> 

      </LinearLayout> 
</ScrollView> 
</RelativeLayout> 

スクロールビューが機能しない。私はstackoverflowからのすべての答えを試みたが、まだこの問題を解決する方法を見つけることができません。 このxmlファイルは断片です。タブ付きビューアクティビティのフラグメントの1つです。フラグメント内でScrollviewが機能しない

EDIT Javaファイル

package mcb.myclickbazaar.Activity; 

import android.net.Uri; 
import android.os.Bundle; 
import android.support.design.widget.TabLayout; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentPagerAdapter; 
import android.support.v4.view.ViewPager; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.util.Log; 
import android.view.Menu; 
import android.view.MenuItem; 

import java.util.ArrayList; 
import java.util.List; 

import mcb.myclickbazaar.Fragments.DateTimePlace; 
import mcb.myclickbazaar.Fragments.FinalBill; 
import mcb.myclickbazaar.Fragments.ItemSelect; 
import mcb.myclickbazaar.R; 

public class ProceedingsActivity extends AppCompatActivity implements ItemSelect.OnFragmentInteractionListener, 
     DateTimePlace.OnFragmentInteractionListener,FinalBill.OnFragmentInteractionListener{ 

    private static final String TAG = "ProceedingsActivity"; 
    private ViewPager mViewPager; 

    private TabLayout tabLayout; 
    private ViewPager viewPager; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_proceedings); 

     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     toolbar = (Toolbar) findViewById(R.id.toolbar); 
     //setSupportActionBar(toolbar); 

     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

     // Create the adapter that will return a fragment for each of the three 
     // primary sections of the activity. 

     viewPager = (ViewPager) findViewById(R.id.viewpager_proceedings); 
     setupViewPager(viewPager); 

     tabLayout = (TabLayout) findViewById(R.id.tabs); 
     tabLayout.setupWithViewPager(viewPager); 


    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_proceedings, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 


    private void setupViewPager(ViewPager viewPager) { 
     ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); 
     adapter.addFragment(new ItemSelect(), "Select"); 
     adapter.addFragment(new DateTimePlace(), "DateTime"); 
     adapter.addFragment(new FinalBill(), "Bill"); 
     viewPager.setAdapter(adapter); 
    } 

    @Override 
    public void onFragmentInteraction(Uri uri) { 

     Log.e(TAG,"Working: on onFragmentInteraction"); 
    } 

    class ViewPagerAdapter extends FragmentPagerAdapter { 
     private final List<Fragment> mFragmentList = new ArrayList<>(); 
     private final List<String> mFragmentTitleList = new ArrayList<>(); 

     public ViewPagerAdapter(FragmentManager manager) { 
      super(manager); 
     } 

     @Override 
     public Fragment getItem(int position) { 
      return mFragmentList.get(position); 
     } 

     @Override 
     public int getCount() { 
      return mFragmentList.size(); 
     } 

     public void addFragment(Fragment fragment, String title) { 
      mFragmentList.add(fragment); 
      mFragmentTitleList.add(title); 
     } 

     @Override 
     public CharSequence getPageTitle(int position) { 
      return mFragmentTitleList.get(position); 
     } 
    } 
} 

断片コード

package mcb.myclickbazaar.Fragments; 

import android.content.Context; 
import android.net.Uri; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.ArrayAdapter; 
import android.widget.EditText; 
import android.widget.Spinner; 

import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.Date; 
import java.util.List; 
import java.util.Locale; 

import mcb.myclickbazaar.R; 

/** 
* A simple {@link Fragment} subclass. 
* Activities that contain this fragment must implement the 
* {@link DateTimePlace.OnFragmentInteractionListener} interface 
* to handle interaction events. 
* Use the {@link DateTimePlace#newInstance} factory method to 
* create an instance of this fragment. 
*/ 
public class DateTimePlace extends Fragment implements AdapterView.OnItemSelectedListener { 
    // TODO: Rename parameter arguments, choose names that match 
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER 
    private static final String ARG_PARAM1 = "param1"; 
    private static final String ARG_PARAM2 = "param2"; 

    // TODO: Rename and change types of parameters 
    private String mParam1; 
    private String mParam2; 
    private String upcoming_date_1,upcoming_date_2,upcoming_date_3,upcoming_date_4; 
    private EditText editText_date; 
    private EditText editText_time; 
    private Spinner spinner_calendar; 
    private Spinner spinner_time; 
    private OnFragmentInteractionListener mListener; 

    public DateTimePlace() { 
     // Required empty public constructor 
    } 

    /** 
    * Use this factory method to create a new instance of 
    * this fragment using the provided parameters. 
    * 
    * @param param1 Parameter 1. 
    * @param param2 Parameter 2. 
    * @return A new instance of fragment DateTimePlace. 
    */ 
    // TODO: Rename and change types and number of parameters 
    public static DateTimePlace newInstance(String param1, String param2) { 
     DateTimePlace fragment = new DateTimePlace(); 
     Bundle args = new Bundle(); 
     args.putString(ARG_PARAM1, param1); 
     args.putString(ARG_PARAM2, param2); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     if (getArguments() != null) { 
      mParam1 = getArguments().getString(ARG_PARAM1); 
      mParam2 = getArguments().getString(ARG_PARAM2); 
     } 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     // Spinner element 
     final View view = inflater.inflate(R.layout.fragment_date_time_place, container, false); 

     spinner_calendar = (Spinner) view.findViewById(R.id.spinner_calender); 
     spinner_time = (Spinner) view.findViewById(R.id.spinner_time); 

     editText_date = (EditText) view.findViewById(R.id.editText_SelectDate_DTP); 
     editText_time = (EditText) view.findViewById(R.id.editText_SelectTime_DTP); 

     editText_date.setFocusable(false); 
     editText_time.setFocusable(false); 

     editText_date.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       spinner_calendar.setVisibility(View.VISIBLE); 
       spinner_calendar.performClick(); 
       editText_date.setHint(""); 
      } 
     }); 

     editText_time.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       spinner_time.setVisibility(View.VISIBLE); 
       spinner_time.performClick(); 
       editText_time.setHint(""); 
      } 
     }); 

     // Spinner click listener 
     spinner_calendar.setOnItemSelectedListener(this); 

     // Spinner Drop down elements 
     List<String> categories_calender = new ArrayList<String>(); 
     categories_calender.add("Today"); 
     categories_calender.add("Tomorrow"); 
     categories_calender.add(getUpcoming_Date(2)); 
     categories_calender.add(getUpcoming_Date(3)); 
     categories_calender.add(getUpcoming_Date(4)); 
     categories_calender.add(getUpcoming_Date(5)); 

     // Creating adapter for spinner 
     ArrayAdapter<String> dataAdapter_calendar = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, categories_calender); 

     // Drop down layout style - list view with radio button 
     dataAdapter_calendar.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

     // attaching data adapter to spinner 
     spinner_calendar.setAdapter(dataAdapter_calendar); 

     // Spinner click listener 
     spinner_time.setOnItemSelectedListener(this); 

     // Spinner Drop down elements 
     List<String> categories_time = new ArrayList<String>(); 
     categories_time.add("9AM - 11AM"); 
     categories_time.add("11AM - 1PM"); 
     categories_time.add("1PM - 3PM"); 
     categories_time.add("3PM - 5PM"); 
     categories_time.add("5PM - 7PM"); 

     // Creating adapter for spinner 
     ArrayAdapter<String> dataAdapter_time = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, categories_time); 

     // Drop down layout style - list view with radio button 
     dataAdapter_time.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

     // attaching data adapter to spinner 
     spinner_time.setAdapter(dataAdapter_time); 



     return view; 
    } 

    private String getUpcoming_Date(int upcoming){ 
     Calendar c = Calendar.getInstance(); 

     Date dt = new Date(); 
     c.add(Calendar.DATE, upcoming); 

     SimpleDateFormat df = new SimpleDateFormat("EEE,dd MMM", Locale.US); 
     String formattedDate = df.format(c.getTime()); 

     return formattedDate; 

    } 

    @Override 
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 
     // On selecting a spinner item 
     String item = parent.getItemAtPosition(position).toString(); 

    } 

    public void onNothingSelected(AdapterView<?> arg0) { 
     // TODO Auto-generated method stub 
    } 
    // TODO: Rename method, update argument and hook method into UI event 
    public void onButtonPressed(Uri uri) { 
     if (mListener != null) { 
      mListener.onFragmentInteraction(uri); 
     } 
    } 

    @Override 
    public void onAttach(Context context) { 
     super.onAttach(context); 
     if (context instanceof OnFragmentInteractionListener) { 
      mListener = (OnFragmentInteractionListener) context; 
     } else { 
      throw new RuntimeException(context.toString() 
        + " must implement OnFragmentInteractionListener"); 
     } 
    } 

    @Override 
    public void onDetach() { 
     super.onDetach(); 
     mListener = null; 
    } 

    /** 
    * This interface must be implemented by activities that contain this 
    * fragment to allow an interaction in this fragment to be communicated 
    * to the activity and potentially other fragments contained in that 
    * activity. 
    * <p> 
    * See the Android Training lesson <a href= 
    * "http://developer.android.com/training/basics/fragments/communicating.html" 
    * >Communicating with Other Fragments</a> for more information. 
    */ 

    public interface OnFragmentInteractionListener { 
     void onFragmentInteraction(Uri uri); 
    } 

} 
+1

NestedScrollviewを使用し、fillviewport = trueを追加します。上の相対レイアウトも削除します –

+0

私は試しましたが、うまくいきませんでした! 少し説明できますか? –

+0

最初にScrollviewをNestedscrollviewに置き換え、androidを削除します。isScrollContainer = "false" line –

答えて

0

はこれを試してみてください。

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

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="10dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="sdsd"/> 

     </LinearLayout> 
    </ScrollView> 
</RelativeLayout> 
0

以下のようにrelativeLayoutとScrollViewの両方のための絶頂match_parentを作るマッチ親とラップコンテンツとして、その中にすべての高さとスクロールビューの高さをキープ。

関連する問題