我正在制作一个具有滚动视图的布局,它有一个多次实现的布局。 问题是,当我在我的设备中运行时,滚动只有在我用一根手指握住它并用另一根手指滑动时才有效
我已经搜索了问题,但我仍然没有答案
这里是xml代码:
<LinearLayout 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"
tools:context="com.example.catarinaferreira.tripmanager.frag_results"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:layout_height="500dp"
>
<!-- TODO: Update blank fragment layout -->
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/id_experience"
android:visibility="gone" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/scroll_results"
android:scrollIndicators="right"
style="@style/DialogFragmentStyle"
android:background="@color/light_orange"
android:scrollbarSize="10dp"
android:overScrollMode="ifContentScrolls"
android:nestedScrollingEnabled="true"
android:focusableInTouchMode="true"
android:focusable="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/results"
android:orientation="vertical"
android:background="@android:color/transparent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout_results"
android:background="@color/white">
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/results_top_information">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:id="@+id/layout_results_exp_name"
android:layout_height="25dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_experience"
android:id="@+id/imageView14"
android:layout_weight="1"
android:layout_width="50dp" />
<Space
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="10dp" />
<TextView
android:text="Passeio às grutas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txt_results_experience"
android:textSize="18sp"
android:textStyle="normal|bold"
android:textColor="@android:color/background_dark"
android:fontFamily="casual" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:id="@+id/layout_results_location"
android:layout_height="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_location"
android:id="@+id/imageView15"
android:layout_width="50dp" />
<Space
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="10dp" />
<TextView
android:text="Marina Albufeira"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txt_results_location"
android:textSize="18sp"
android:textColor="@android:color/background_dark"
android:fontFamily="sans-serif" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:id="@+id/layout_results_boat">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_boat"
android:id="@+id/imageView16"
android:layout_width="50dp" />
<Space
android:layout_height="match_parent"
android:layout_width="10dp" />
<TextView
android:text="Golfinho"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txt_results_boat"
android:textSize="16sp"
android:textColor="@android:color/background_dark"
android:fontFamily="casual" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<ImageView
android:layout_width="match_parent"
app:srcCompat="@drawable/experience"
android:id="@+id/img_results_experience"
android:layout_height="150dp"
android:scaleType="centerCrop" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="@+id/results_date_time"
android:layout_height="15dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/layout_results_date">
<ImageView
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_calendar"
android:id="@+id/imageView19"
android:layout_weight="1"
android:layout_width="20dp" />
<Space
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="5dp" />
<TextView
android:text="23/02/2017"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txt_results_date"
android:layout_weight="1"
android:textColor="@android:color/black"
android:textSize="14sp" />
<Space
android:layout_width="20dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/layout_results_time">
<ImageView
android:layout_width="20dp"
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_time"
android:id="@+id/imageView20"
android:layout_weight="1" />
<Space
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<TextView
android:text="07:00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txt_results_time"
android:layout_weight="1"
android:textSize="14sp"
android:textColor="@android:color/black" />
<Space
android:layout_width="20dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/layout_results_duration">
<ImageView
android:layout_width="20dp"
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_duration"
android:id="@+id/imageView21"
android:layout_weight="1" />
<Space
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<TextView
android:text="01:00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txt_results_duration"
android:layout_weight="1"
android:textSize="14sp"
android:textColor="@android:color/black" />
</LinearLayout>
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_height="match_parent"
android:id="@+id/results_prices"
android:layout_width="match_parent">
<ImageView
app:srcCompat="@drawable/ic_prices"
android:id="@+id/imageView22"
android:layout_weight="1"
android:foregroundGravity="top"
android:layout_gravity="top"
android:layout_width="50dp"
android:layout_height="50dp" />
<Space
android:layout_height="match_parent"
android:layout_width="10dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/layout_results_price_list">
<TextView
android:text="Preços"
android:layout_width="match_parent"
android:id="@+id/txt_price_name"
android:fontFamily="casual"
android:textStyle="normal|bold"
android:textSize="18sp"
android:textColor="@android:color/black"
android:layout_height="25dp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@color/laranja_logo">
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_weight="1" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout_set_prices"></LinearLayout>
</LinearLayout>
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="#ffe0be"
android:id="@+id/results_more_informations"
android:layout_height="25dp">
<Space
android:layout_width="10dp"
android:layout_height="match_parent" />
<ImageView
app:srcCompat="@drawable/ic_plus"
android:id="@+id/img_more_informations"
android:layout_height="match_parent"
android:clickable="true"
android:layout_width="30dp" />
<TextView
android:text="Mais informações"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/txt_more_informations"
android:layout_weight="1"
android:textSize="18sp"
android:textStyle="normal|bold"
android:textColor="@android:color/background_dark"
android:foregroundGravity="center"
android:gravity="center" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<TextView
android:text="25 lugares disponíveis"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txt_disponibility"
android:gravity="center"
android:background="@android:color/holo_green_light"
android:textColor="@android:color/black" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<Button
android:text="Reservar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn_reservation"
android:background="@color/azul_logo"
android:textColor="@android:color/background_light"
android:textStyle="normal|bold"
android:textSize="24sp"
android:fontFamily="casual"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
这里是片段代码:
public class frag_results extends Fragment {
public frag_results() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View myinflatedview = inflater.inflate(R.layout.fragment_frag_results, container, false);
LinearLayout results_layout = (LinearLayout) myinflatedview.findViewById(R.id.results);
LinearLayout to_hide = (LinearLayout)myinflatedview.findViewById(R.id.layout_results); //Layout for using multiple times
to_hide.setVisibility(View.GONE); //We set that gone so we can build all of the other ones in a for cicle
final View myScroll = (View) myinflatedview.findViewById(R.id.scroll_results);
ScrollView scroll_view = (ScrollView)myinflatedview.findViewById(R.id.scroll_results);
for (int n = 0; n < 5; n++) { }//Builds the results
//SOME CODE FOR BUILDING THE SAME LAYOUT MULTIPLE TIMES
return myinflatedview;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//When clicked in "plus" image, it opens the fragment "more informations"
ImageView img_more_informations = (ImageView) getActivity().findViewById(R.id.img_more_informations);
img_more_informations.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { frag_more_informations frag_more_informations = new frag_more_informations();
FragmentManager manager = getActivity().getSupportFragmentManager();
manager.beginTransaction().replace(R.id.framelayout_secundary, frag_more_informations, frag_more_informations.getTag()).commit();
}
});
}
@Override
//Pressed return button - returns to the home menu
public void onResume() {
super.onResume();
getView().setFocusableInTouchMode(true);
getView().requestFocus();
getView().setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK){
View show_layout_secundary = (View)getActivity().findViewById(R.id.framelayout_secundary); //LAYOUT - SHOWS SECUNDARY PAGES
View show_layout_principal = (View)getActivity().findViewById(R.id.framelayout_principal); //LAYOUT - SHOWS INITIAL PAGE
show_layout_principal.setVisibility(View.VISIBLE);
show_layout_secundary.setVisibility(View.INVISIBLE);
return true;
}
return false;
}
});
}
答案 0 :(得分:0)
它有一个愚蠢的解决方案!
我们只需要使用CoordinatorLayout
NestedScrollView