2016-12-22 19 views
0

我正在嘗試爲Android應用程序進行登錄活動。 App在Potrait模式下工作正常,但在橫向模式下,UI無法完全容納,因此UI的一部分不可見。我提到了所有相關的SO問題,但沒有任何幫助。
設備 - 摩托羅拉X型棉花糖
無法制作UI可滾動

代碼activity_login.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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" 
    tools:context=".SignupActivity" 
    android:scrollbars="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/MyMaterialTheme.AppBarOverlay"> 

     <include android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      layout="@layout/toolbar" /> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_login" /> 
</android.support.design.widget.CoordinatorLayout> 

代碼content_login.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    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:background="#1E1E24" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context=".SignupActivity" 
    tools:showIn="@layout/activity_login"> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:id="@+id/first" 
     android:textColor="@color/primary_text_default_material_dark" 
     android:textSize="@dimen/title_font" 
     android:textStyle="bold" 
     android:layout_marginBottom="@dimen/padding_10" 
     android:text="Login Activity" 
     /> 

    <View 
     android:id="@+id/second" 
     android:layout_width="match_parent" 
     android:layout_below="@id/first" 
     android:layout_height="@dimen/contacting_post_staff_view_width" 
     android:background="@color/photo_border"/> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:id="@+id/third" 
     android:layout_below="@id/second" 
     android:textColor="@color/primary_text_default_material_dark" 
     android:textSize="@dimen/sub_title_font" 
     android:textStyle="bold" 
     android:layout_marginTop="@dimen/padding_10" 
     android:text="Hey ! This is a sample App for Login Activity" 
     /> 


    <LinearLayout 
     android:layout_marginTop="@dimen/fragment_main_marginTop_35" 
     android:layout_width="match_parent" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:layout_below="@id/third" 
     android:layout_height="wrap_content"> 
     <EditText 
      android:background="@drawable/edit_text_bg" 
      android:layout_width="match_parent" 
      android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15" 
      android:layout_height="wrap_content" 
      android:id="@+id/edit_name" 
      android:hint="@string/enter_name" 
      android:inputType="textPersonName|textCapWords" /> 

     <Spinner 
      android:id="@+id/spinner_country" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:dropDownWidth="@dimen/contacting_post_staff_spinner_width" 
      android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15" /> 
     <Button 
      android:id="@+id/loginButton" 
      style="@style/NavigateButton" 
      android:text="@string/login" 
      android:layout_marginTop="@dimen/fragment_main_marginTop_35"/> 

    </LinearLayout> 



</RelativeLayout> 

代碼toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" android:layout_height="wrap_content" 
    android:id="@+id/toolbar" 
    android:background="@color/background_textview" 
    android:minHeight="?attr/actionBarSize" 
    android:fitsSystemWindows="true" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    > 
</android.support.v7.widget.Toolbar> 

爲了解決這個問題,我正在嘗試使用戶界面可滾動,以便用戶可以滾動到在橫向模式下不可見的部分。

我曾嘗試 -

1.我試圖把下面內部滾動型

包括佈局= 「@佈局/ content_login」/>

2 I試圖把在線性佈局內部,然後在滾動視圖內線性佈局。

還有很多其他的事情我玩,但沒有任何幫助。 請幫我這個。非常感謝。

回答

0

嘗試將content_login.xml的根元素設置爲滾動視圖。 您可以在新的滾動視圖中使用當前相對佈局嵌套佈局。

或者,您可以在AndroidManifest.xml中的activity標籤下使用android:screenOrientation =「portrait」將活動方向修復爲縱向,如果它不是問題。

另外,考慮使用ConstraintLayout,它消除了處理嵌套佈局的麻煩。

+0

非常感謝!您的第一種方法可以進行一些小的更改。 –

+0

很高興能有一些幫助! – sats

0
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".SignupActivity"> 

<ScrollView 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context=".SignupActivity" 
     android:orientation="vertical" 
     tools:showIn="@layout/activity_login"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:id="@+id/first" 
      android:textColor="@color/primary_text_default_material_dark" 
      android:textSize="@dimen/title_font" 
      android:textStyle="bold" 
      android:layout_marginBottom="@dimen/padding_10" 
      android:text="Login Activity" 
      /> 

     <View 
      android:id="@+id/second" 
      android:layout_width="match_parent" 
      android:layout_below="@id/first" 
      android:layout_height="@dimen/contacting_post_staff_view_width" 
      android:background="@color/photo_border"/> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:id="@+id/third" 
      android:layout_below="@id/second" 
      android:textColor="@color/primary_text_default_material_dark" 
      android:textSize="@dimen/sub_title_font" 
      android:textStyle="bold" 
      android:layout_marginTop="@dimen/padding_10" 
      android:text="Hey ! This is a sample App for Login Activity" 
      /> 


     <LinearLayout 
      android:layout_marginTop="@dimen/fragment_main_marginTop_35" 
      android:layout_width="match_parent" 
      android:orientation="vertical" 
      android:gravity="center" 
      android:layout_below="@id/third" 
      android:layout_height="wrap_content"> 
      <EditText 
       android:background="@drawable/edit_text_bg" 
       android:layout_width="match_parent" 
       android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15" 
       android:layout_height="wrap_content" 
       android:id="@+id/edit_name" 
       android:hint="@string/enter_name" 
       android:inputType="textPersonName|textCapWords" /> 

      <Spinner 
       android:id="@+id/spinner_country" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:dropDownWidth="@dimen/contacting_post_staff_spinner_width" 
       android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15" /> 
      <Button 
       android:id="@+id/loginButton" 
       style="@style/NavigateButton" 
       android:text="@string/login" 
       android:layout_marginTop="@dimen/fragment_main_marginTop_35"/> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

試試這個,添加所有的填充,邊距,高度,寬度等,只要你想,所有的佈局限制