问题
For some reason scrolling is not getting activated. I want to have that black place cover half the screen also. But if I change that height of ScrollView to wrap content then this black space disappears.
This black space will have photo thats why I need it to cover at least half.
I used layout weight for it but because the pictures are dynamicly loaded I have to reserve the space. Currently in this code it reserves half of the screen but Scrool does not get activated and other items are not visible.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e0e0e0"
android:fadeScrollbars="false"
android:fillViewport="true"
tools:context="com.example.Test.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e0e0e0"
android:orientation="vertical"
android:weightSum="4">
<LinearLayout
android:id="@+id/level1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#e0e0e0"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/vk_white">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/black"
android:scaleType="fitXY" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/level2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="@color/vk_white"
android:orientation="vertical">
<TextView
android:id="@+id/temelBilgilerInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:text="@string/temelbilgileriinfo"
android:textColor="@android:color/black"
android:textSize="20dp" />
<View
android:id="@+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/temelBilgilerInfo"
android:background="@drawable/ruhesi_lines" />
<EditText
android:id="@+id/birthday_edit"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/layout_root"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit1"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit3"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit2"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit4"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit3"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday1"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit5"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit4"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday123213"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit7"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit6"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit8"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit7"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
android:gravity="center_horizontal"/>
<EditText
android:id="@+id/birthday_edit9"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit8"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit10"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit9"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit11"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit10"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit12"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit11"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit13"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit12"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter asd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Not working
回答1:
Answer is also located:
ScrollView with two views, first view filling screen
What I did was to programmaticly arrange that space for the pager. This part of the other answer was useful for me.
layout = (LinearLayout)findViewById(R.id.linlayout);
f1=(FrameLayout) findViewById(R.id.f1);
f2=(FrameLayout) findViewById(R.id.f2);
ViewTreeObserver vto = layout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int width = layout.getMeasuredWidth();
int height = layout.getMeasuredHeight();
f1.setLayoutParams(new LayoutParams(width, height));
f2.setLayoutParams(new LayoutParams(width, height));
}
});
回答2:
i check your xml layout and I see that you don't close the ScrollView Correctly.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e0e0e0"
android:orientation="vertical"
>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY" />
<TextView
android:id="@+id/temelBilgilerInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:textColor="@android:color/black"
android:textSize="20dp" />
<View
android:id="@+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/temelBilgilerInfo"
/>
<EditText
android:id="@+id/birthday_edit"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/layout_root"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit1"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit3"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit2"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit4"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit3"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday1"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit5"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit4"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthday123213"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit7"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit6"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit8"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit7"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
android:gravity="center_horizontal"/>
<EditText
android:id="@+id/birthday_edit9"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit8"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit10"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit9"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit11"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit10"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit12"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit11"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter Birthdayasdasdasd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
<EditText
android:id="@+id/birthday_edit13"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/birthday_edit12"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="Enter asd"
android:inputType="date"
android:textColor="#000000"
android:textColorHint="#DDAAAAAA" />
</LinearLayout>
</ScrollView>
this code goes inside your Scrollview hope it helps!!!!!!!!!
来源:https://stackoverflow.com/questions/35209107/why-is-my-android-scrollview-not-scrolling