1
我在List Fragment中實現了Twitter SDK
。它像Twitter一樣擁有無限的滾動條。但是,當我嘗試在scrollview layout
中添加此片段時,它將禁用scrollview
的twitter fragment
。如何在片段中添加滾動
public class TwitterFragment extends ListFragment {
public static TwitterFragment newInstance() {
return new TwitterFragment();
}
佈局
<TextView
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:text="No Tweets" />
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="50dp"
android:layout_weight="1"
android:divider="#e1e8ed"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false" />
</LinearLayout>
現在我想在另一個活動添加此片段。 MainActivity
已經有一個滾動視圖。當我在那裏添加這個片段時,twitter片段的滾動消失了。我嘗試了各種方法,但未能實現目標。
我需要在小片段中同樣無限滾動。
這是我的MainActivity
代碼。
<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:id="@+id/content_users_feedback"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.myapp.app.usersreviews.reviews"
android:background="@drawable/users_bg"
tools:showIn="@layout/activity_user_reviews">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:isScrollContainer="false"
android:id="@+id/scroll_view"
android:layout_below="@+id/sv_users"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!-- USER DATA-->
<include layout="@layout/users_data_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/layout_data"
/>
<!-- TWITTER-->
<TextView
android:id="@+id/textView8"
android:layout_width="match_parent"
android:layout_height="33.62dp"
android:background="#054F92"
android:gravity="center_vertical"
android:text="\@tweets"
android:textColor="@android:color/white"
android:textSize="16sp"
android:paddingLeft="15dp"
android:textStyle="normal|bold" />
<fragment
android:id="@+id/cart_twitter_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-50dp"
android:nestedScrollingEnabled="true"
class="com.myapp.app.TwitterFragment"
tools:layout="@layout/fragment_twitter" />
<!-- TWITTER -->
</LinearLayout>
</ScrollView>
</RelativeLayout>
只是爲了確認創建的滾動型一個實例,做用戶數據列表包含它需要滾動的數據太多了? – clownba0t
@ clownba0t,是的,它有很多數據,我沒有在問題中添加所有視圖 – Kirmani88
我的理解是,通常不建議嵌套'ScrollView',至少部分是因爲可能難以確定哪個他們應該處理任何給定的輕掃手勢。看來你遇到了這個問題。我建議改變數據的呈現方式。考慮在活動佈局中移動「ScrollView」,以便它僅包裝用戶數據列表。這樣你有兩個滾動佈局,但它們沒有嵌套。然後,您可以設置片段的寬度,高度,重量等,並通過滾動視圖來實現所需的UI,同時仍然允許滾動。 – clownba0t