我正在使用ScrollView
的布局。我的布局打开后,我无法查看所有项目
我无法向下滚动完成,但在EditText
中编辑内容后,如果我再次滚动“我能够查看所有项目”。
请帮助解决这个问题。
以下是我的布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_alignParentTop="true"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Diabetes Risk Assesment"
android:textStyle="bold"
android:gravity="center"
android:textSize="20dp"
android:textColor="#00abea"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_diabetesage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp">
<EditText
android:id="@+id/input_diabetes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="number"
android:hint="@string/hint_age"
/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Gender"
android:paddingTop="20dp"
android:textSize="15dp"
android:textStyle="bold"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:id="@+id/diaradiogroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="@+id/rmale"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="@+id/rfemale"/>
</RadioGroup>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_diabeteswaist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp">
<EditText
android:id="@+id/input_waist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="number"
android:hint="@string/hint_waist"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/strexercise"
android:paddingTop="20dp"
android:textSize="15dp"
android:textStyle="bold"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:id="@+id/diaexxercise">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yes"
android:id="@+id/remale"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No"
android:id="@+id/refemale"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/strexercisedaily"
android:paddingTop="20dp"
android:textSize="15dp"
android:textStyle="bold"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:id="@+id/exercisedaily">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yes"
android:id="@+id/redmale"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No"
android:id="@+id/redfemale"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/strparents"
android:paddingTop="20dp"
android:textSize="15dp"
android:textStyle="bold"/>
<Spinner
android:id="@+id/spingender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/spinner_style"
/>
</LinearLayout>
<!--<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>-->
</LinearLayout>
</ScrollView>
答案 0 :(得分:0)
也许那是因为您的EditText
默认是专注的。
您可以在活动的onCreate()
中添加此行来删除该行。
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
希望这会有所帮助:)
答案 1 :(得分:0)
经过几个小时的搜索,我找到了解决问题的方法。
在scrollview中添加此属性 - app:layout_behavior =&#34; @ string / appbar_scrolling_view_behavior&#34;
并从ViewPager中删除相同的属性
所以ScrollView的布局应该在
之下<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">
和ViewPager应该是这样的
<android.support.v4.view.ViewPager
android:id="@+id/viewpager2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>