PercentRelativeLayout внутри ScrollView
Я создал макет, используяScrollView
который имеетPercentRelativeLayout
как его ребенок. Он не работает на Lollipop и более старых устройствах, но отлично работает на устройствах Marshmallow. Пожалуйста, проверьте код ниже:
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<android.support.percent.PercentRelativeLayout
android:id="@+id/scrollContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_heightPercent="100%"
app:layout_widthPercent="50%">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_dark"
android:text="kkjknadko"
android:textColor="@android:color/black"
app:layout_heightPercent="10%"
app:layout_widthPercent="50%"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:text="Abcaad"
android:textColor="@android:color/black"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="10%"
app:layout_widthPercent="50%"/>
<TextView
android:id="@+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview2"
android:background="@android:color/holo_red_dark"
android:text="Abcd"
android:textColor="@android:color/black"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="10%"
app:layout_widthPercent="50%"/>
<TextView
android:id="@+id/textview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview3"
android:text="Abcd"
android:textColor="@android:color/black"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="10%"
app:layout_widthPercent="50%"/>
<TextView
android:id="@+id/textview5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview4"
android:background="@android:color/holo_red_dark"
android:text="Abcd"
android:textColor="@android:color/black"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="10%"
app:layout_widthPercent="50%"/>
<TextView
android:id="@+id/textview6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview5"
android:text="Abcd"
android:textColor="@android:color/black"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="10%"
app:layout_widthPercent="50%"/>
<TextView
android:id="@+id/textview7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview6"
android:text="Abcd"
android:textColor="@android:color/black"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="10%"
app:layout_widthPercent="50%"/>
<TextView
android:id="@+id/textview8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview7"
android:text="Abcd"
android:textColor="@android:color/black"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="10%"
app:layout_widthPercent="50%"/>
</android.support.percent.PercentRelativeLayout>
</ScrollView>
А также яandroid:fillViewport="true"
ничего не показывает в Lollipop и более старых версиях Android.
К сожалению, процентное расположение не будет работать сScrollView
до М. Причиной этого является то, что они зависят от подсказки размера, доставляемой на этапе измерения. До M большинство макетов предоставит подсказку о размере 0 при отправке неуказанной спецификации меры.
Вы можете попытаться исправить это, создав собственный подклассScrollView
и переопределениеmeasureChild
а такжеmeasureChildWithMargins
(к счастью, оба защищены), чтобы обеспечить подсказку размера.
источник - plus.google.com.
Может кто-нибудь помочь мне с созданием кастомаScrollView
заставить это работать?