我在选项卡式活动片段占位符中以编程方式实现了滚动视图。我的代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_algorithm, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
String[] array = {"Hi from description", "Hi from C", "Hi from JAVA"};
array[0] = "Hi! this is the first program of asdk your carrier into computer coding. This code shows you how to print Hello World on the console of the computer!\n\nHere is the Image ``Image:calender`` \n\nThis image shows you how this program works! Wohoo you learnt the first ``Image:star`` algo of your life. sdiaj isja dias dsa djsa djas sadksf dsfsdmf sdf ldsf ldsfsdl fsdkf s fsd lksd flsdkl flkds lsdkflklsdk flksdlfklsdl fklsdkl flsdkf klkd b jj bbb jhbhb hjbhj bjh bhjbhjbhjb jbhjb hjbhbhbhjbhbhbhhjb hbhjbh b hjb hj bhjbhj hb hjb ``Image:youtube`` jh bhjbhjbhjhbh bbhskflkldsl";
ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.abcscrollView);
RelativeLayout relativeLayout = new RelativeLayout(rootView.getContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
relativeLayout.setLayoutParams(params);
if(getArguments().getInt(ARG_SECTION_NUMBER)-1==0) {
String temparray[] = array[0].split("``");
array[0] = "";
for (int i = 0; i < temparray.length; i++) {
if (temparray[i].startsWith("Image:")) {
ImageView iv = new ImageView(rootView.getContext());
iv.setId(i+1);
int itd = this.getResources().getIdentifier(temparray[i].substring(6), "drawable", getActivity().getPackageName());
iv.setImageResource(itd);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
if (i > 0) {
params1.addRule(RelativeLayout.BELOW, i);
}
relativeLayout.addView(iv, params1);
} else {
TextView tv = new TextView(rootView.getContext());
tv.setText(temparray[i]);
tv.setId(i+1);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
if (i > 0) {
params1.addRule(RelativeLayout.BELOW, i);
}
relativeLayout.addView(tv, params1);
}
// array[0]+=temparray[i];
}
}
ScrollView.LayoutParams params2 = new ScrollView.LayoutParams (ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.MATCH_PARENT);
scrollView.addView (relativeLayout, params2);
textView.setText (array[getArguments ().getInt (ARG_SECTION_NUMBER) - 1]);
return rootView;
}
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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.suvariyaraj.algorithms.AlgorithmActivity$PlaceholderFragment">
<ScrollView
android:id="@+id/abcscrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
但是我无法滚动到最后。 screenshot of the app
在这里,您可以看到,即使滚动视图到达结尾,YouTube图标也是一半可见。
请帮帮我。
以下是“adb shell dumpsys activity top”
的输出TASK com.facebook.katana id=2647
ACTIVITY com.facebook.katana/.activity.ImmersiveActivity 431f2cd8 pid=27958
Local FragmentActivity 432394e0 State:
mCreated=truemResumed=false mStopped=true mReallyStopped=true
mLoadersStarted=false
FragmentManager misc state:
mActivity=android.support.v4.app.FragmentActivityHost@4324a178
mContainer=android.support.v4.app.FragmentActivity$2@432405c0
mCurState=2 mStateSaved=true mDestroyed=false
View Hierarchy:
com.android.internal.policy.impl.PhoneWindow$DecorView{43253b08 V.E..... ... 0,0-0,0}
android.widget.LinearLayout{43254620 V.E..... ... 0,0-0,0}
android.view.ViewStub{43257f68 G.E..... ... 0,0-0,0 #1020315}
android.widget.FrameLayout{432581c8 V.E..... ... 0,0-0,0 #1020002 android:id/content}
android.view.ViewStub{432589c0 G.E..... ... 0,0-0,0 #7f0d0a13}
android.view.ViewStub{43258bc8 G.E..... ... 0,0-0,0 #7f0d0a0f}
android.widget.FrameLayout{43258e20 V.E..... ... 0,0-0,0 #7f0d04bd app:id/main_container}
android.widget.FrameLayout{43259158 V.E..... ... 0,0-0,0 #7f0d000c app:id/fragment_container}
com.facebook.ui.titlebar.search.Fb4aFadingTitleBar{432599c8 V.E..... ... 0,0-0,0 #7f0d00ae app:id/titlebar}
com.facebook.fbui.glyph.GlyphView{4325ab50 V.ED..C. ... 0,0-0,0 #7f0d248d app:id/fb_logo_up_button}
android.widget.FrameLayout{4325afd8 V.E..... ... 0,0-0,0 #7f0d248e app:id/info_container}
com.facebook.resources.ui.FbTextView{4325b398 V.ED..C. ... 0,0-0,0 #7f0d0200 app:id/title}
android.widget.FrameLayout{4325c230 G.E..... ... 0,0-0,0 #7f0d248f app:id/custom_title_wrapper}
android.view.ViewStub{4325c5f0 G.E..... ... 0,0-0,0 #7f0d2490}
android.widget.LinearLayout{4325c888 V.E..... ... 0,0-0,0 #7f0d2491 app:id/action_buttons_wrapper}
com.facebook.fbui.glyph.GlyphView{43262810 V.ED..C. ... 0,0-0,0 #7f0d02ce app:id/search_button}
android.view.ViewStub{4325ef30 G.E..... ... 0,0-0,0 #7f0d0329}
android.widget.FrameLayout{4325fe90 V.E..... ... 0,0-0,0 #7f0d070b app:id/fullscreen_container}