以下是我的xml
部分布局在屏幕下方不适用,因此我在父ScrollView
上应用了LinearLayout
,线性布局应用重量但是当我试图滚动该布局时它不滚动。任何人都可以建议我在ScrollView
没有处理体重LinearLayout
时,我在哪里以及我做错了什么?
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="2"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="@dimen/baseline_grid_7x"
android:paddingRight="@dimen/baseline_grid_7x"
android:paddingTop="@dimen/baseline_grid_7x">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:adapter="@{imageSlideradapter}"
app:currentItem="@{landingLoginViewModel.currentPage}"
android:addOnPageChangeListener="@{landingLoginViewModel.pageChangeListener}"/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/indicator"
android:fontFamily="sans-serif"
android:gravity="center_horizontal"
android:lineSpacingExtra="@dimen/text_land_spacing"
android:paddingTop="@dimen/layout_padding_top"
android:text="@string/label_businesscard_title"
android:textColor="#3e4360"
android:textSize="@dimen/businees_card_textmessage_size"
android:textStyle="normal" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingTop="@dimen/padding_top_15dp"
app:centered="true"
app:fillColor="#1ebad6"
app:radius="@{landingLoginViewModel.pagerIndicatorCircle}"
app:pageColor="#c6caca"
app:snap="false" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="@dimen/baseline_grid_2.5x"
android:paddingRight="@dimen/baseline_grid_2.5x"
android:paddingTop="@dimen/baseline_grid_5x">
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_signin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/buttonbackroudnd"
android:onClick="@{()->landingLoginViewModel.onSignIn()}"
android:text="@string/label_sign_in"
android:textColor="#ffffff" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_signin"
android:layout_marginTop="@dimen/baseline_grid_3.5x"
android:background="@drawable/roundbuttonborder"
android:onClick="@{()->landingLoginViewModel.onSignUp()}"
android:text="@string/label_sign_up"
android:textColor="#00becc" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/oRtextLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_signup"
android:layout_marginTop="@dimen/baseline_grid_5.5x"
android:fontFamily="sans-serif"
android:gravity="center"
android:text="@string/label_or"
android:textColor="#8998a7"
android:textSize="14sp"
android:textStyle="normal"
/>
<LinearLayout
android:id="@+id/linearlayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/oRtextLabel"
android:gravity="center"
android:onClick="@{()->landingLoginViewModel.onFacebook()}"
android:orientation="horizontal"
android:layout_marginTop="@dimen/baseline_grid_5x">
<ImageView
android:layout_width="@dimen/baseline_grid_3.5x"
android:layout_height="@dimen/baseline_grid_3.5x"
android:src="@drawable/fb_icon" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:paddingLeft="@dimen/baseline_grid_1x"
android:text="@string/label_fcebook"
android:textColor="#465892"
android:textSize="@dimen/baseline_grid_2x"
android:textStyle="normal"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
答案 0 :(得分:1)
ScrollView 正在运行,请查看以下布局
注意:更改了小部件,高度和填充,并且具有固定的高度,以便RelativeLayout检查ScrollView
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="7dp">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/indicator"
android:fontFamily="sans-serif"
android:gravity="center_horizontal"
android:lineSpacingExtra="5dp"
android:paddingTop="5dp"
android:text="label_businesscard_title"
android:textColor="#3e4360"
android:textSize="5dp"
android:textStyle="normal" />
<android.support.v4.view.ViewPager
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingTop="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp">
<Button
android:id="@+id/btn_signin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="label_sign_in"
android:textColor="#ffffff" />
<Button
android:id="@+id/btn_signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_signin"
android:layout_marginTop="5dp"
android:text="label_sign_up"
android:textColor="#00becc" />
<TextView
android:id="@+id/oRtextLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_signup"
android:layout_marginTop="7dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:text="label_or"
android:textColor="#8998a7"
android:textSize="14sp"
android:textStyle="normal" />
<LinearLayout
android:id="@+id/linearlayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/oRtextLabel"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:paddingLeft="5dp"
android:text="label_fcebook"
android:textColor="#465892"
android:textSize="16dp"
android:textStyle="normal" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
答案 1 :(得分:0)
用这个替换你的xml:
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:weightSum="2"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="@dimen/baseline_grid_7x"
android:paddingRight="@dimen/baseline_grid_7x"
android:paddingTop="@dimen/baseline_grid_7x">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:adapter="@{imageSlideradapter}"
app:currentItem="@{landingLoginViewModel.currentPage}"
android:addOnPageChangeListener="@{landingLoginViewModel.pageChangeListener}"/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/indicator"
android:fontFamily="sans-serif"
android:gravity="center_horizontal"
android:lineSpacingExtra="@dimen/text_land_spacing"
android:paddingTop="@dimen/layout_padding_top"
android:text="@string/label_businesscard_title"
android:textColor="#3e4360"
android:textSize="@dimen/businees_card_textmessage_size"
android:textStyle="normal" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingTop="@dimen/padding_top_15dp"
app:centered="true"
app:fillColor="#1ebad6"
app:radius="@{landingLoginViewModel.pagerIndicatorCircle}"
app:pageColor="#c6caca"
app:snap="false" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="@dimen/baseline_grid_2.5x"
android:paddingRight="@dimen/baseline_grid_2.5x"
android:paddingTop="@dimen/baseline_grid_5x">
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_signin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/buttonbackroudnd"
android:onClick="@{()->landingLoginViewModel.onSignIn()}"
android:text="@string/label_sign_in"
android:textColor="#ffffff" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_signin"
android:layout_marginTop="@dimen/baseline_grid_3.5x"
android:background="@drawable/roundbuttonborder"
android:onClick="@{()->landingLoginViewModel.onSignUp()}"
android:text="@string/label_sign_up"
android:textColor="#00becc" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/oRtextLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_signup"
android:layout_marginTop="@dimen/baseline_grid_5.5x"
android:fontFamily="sans-serif"
android:gravity="center"
android:text="@string/label_or"
android:textColor="#8998a7"
android:textSize="14sp"
android:textStyle="normal"
/>
<LinearLayout
android:id="@+id/linearlayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/oRtextLabel"
android:gravity="center"
android:onClick="@{()->landingLoginViewModel.onFacebook()}"
android:orientation="horizontal"
android:layout_marginTop="@dimen/baseline_grid_5x">
<ImageView
android:layout_width="@dimen/baseline_grid_3.5x"
android:layout_height="@dimen/baseline_grid_3.5x"
android:src="@drawable/fb_icon" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:paddingLeft="@dimen/baseline_grid_1x"
android:text="@string/label_fcebook"
android:textColor="#465892"
android:textSize="@dimen/baseline_grid_2x"
android:textStyle="normal"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>