2016-08-06 12 views
12

Tôi đang làm việc trên bố cục nơi tôi đã căn chỉnh cardview ở giữa màn hình và liên hệ với chúng tôi button ở cuối màn hình. Bố cục này trông OK khi bàn phím bị đóng.Chế độ xem dưới cùng của phụ huynh ẩn với chế độ xem bố cục chính giữa trên bàn phím mở

Dường như dưới đây: - enter image description here

Layout.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:weightSum="2"> 

       <ImageView 
        android:id="@+id/login_image" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:background="@drawable/login_background" /> 

       <View 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:background="@color/grey_background" /> 

      </LinearLayout> 


      <android.support.v7.widget.CardView 
       android:id="@+id/media_card_view" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:layout_marginLeft="24dp" 
       android:layout_marginRight="24dp" 
       card_view:cardBackgroundColor="@color/white" 
       card_view:cardElevation="4dp" 
       card_view:cardCornerRadius="5dp" 
       > 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 

        > 

        <ImageView 
         android:id="@+id/logoImageView" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:background="@color/grey_background" 
         android:padding="15dp" 
         android:src="@drawable/logo_login" 
         /> 

        <EditText 
         android:id="@+id/usertext" 
         android:layout_width="match_parent" 
         android:layout_height="40dp" 
         android:layout_below="@id/logoImageView" 
         android:layout_marginLeft="20dp" 
         android:layout_marginRight="20dp" 
         android:layout_marginTop="20dp" 
         android:background="@drawable/edittext_background" 
         android:hint="User ID" 
         android:maxLength="50" 
         android:padding="10dp" 
         android:singleLine="true" 
         android:textColorHint="@color/hint_text_color" 
         android:textSize="16sp" /> 


        <FrameLayout 
         android:id="@+id/passwordLayout" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_below="@id/usertext" 
         android:layout_marginTop="8dp" 
         android:orientation="horizontal"> 

         <EditText 
          android:id="@+id/passtext" 
          android:layout_width="match_parent" 
          android:layout_height="40dp" 
          android:layout_marginLeft="20dp" 
          android:layout_marginRight="20dp" 
          android:background="@drawable/edittext_background" 
          android:fontFamily="sans-serif" 
          android:hint="@string/password" 
          android:inputType="textPassword" 
          android:maxLength="50" 
          android:padding="10dp" 
          android:singleLine="true" 
          android:textColorHint="@color/hint_text_color" 
          android:textSize="16sp" /> 

         <ImageView 
          android:id="@+id/passwordeye" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_gravity="right|center_vertical" 
          android:padding="8dp" 
          android:layout_marginRight="25dp" 
          android:src="@drawable/eye_close" /> 

        </FrameLayout> 

        <LinearLayout 
         android:id="@+id/termsLayout" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_below="@id/passwordLayout" 
         android:layout_marginLeft="15dp" 
         android:layout_marginRight="20dp" 
         android:layout_marginTop="15dp" 
         android:gravity="center" 
         android:orientation="horizontal"> 


         <ImageView 
          android:id="@+id/check_box" 
          android:layout_width="wrap_content" 

          android:layout_height="wrap_content" 
          android:padding="5dp" 
          android:src="@drawable/checkbox_checked" /> 

         <TextView 
          android:id="@+id/terms_and_cond" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="5dp" 
          android:textColor="@color/black" 
          android:textColorLink="#80000000" 
          android:textSize="13sp" /> 
        </LinearLayout> 

        <View 
         android:id="@+id/lineView" 
         android:layout_width="match_parent" 
         android:layout_height="1dp" 
         android:layout_below="@id/termsLayout" 
         android:layout_marginTop="15dp" 
         android:background="@color/grey_background" /> 

        <LinearLayout 
         android:id="@+id/newuser_login_layout" 
         android:layout_width="match_parent" 
         android:layout_height="50dp" 
         android:background="@color/dark_grey" 
         android:layout_below="@id/lineView" 
         android:orientation="horizontal"> 


         <TextView 
          android:id="@+id/newUserButton" 
          android:layout_width="0dp" 
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:background="@drawable/translucent_round_button" 
          android:gravity="center" 
          android:text="New User ?" 
          android:textColor="@color/grey_text_color" 
          android:textSize="17sp" /> 

         <TextView 
          android:id="@+id/loginbutton" 
          android:layout_width="0dp" 
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:background="@drawable/bottom_round_button" 
          android:gravity="center" 
          android:text="Login" 
          android:textColor="@color/white" 
          android:textSize="17sp" /> 

        </LinearLayout> 
       </RelativeLayout> 
      </android.support.v7.widget.CardView> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:orientation="vertical"> 


       <TextView 
        android:id="@+id/contactus_button" 
        android:layout_width="wrap_content" 
        android:layout_height="35dp" 
        android:layout_centerHorizontal="true" 
        android:layout_marginBottom="15dp" 
        android:background="@drawable/contact_us_selector" 
        android:drawableLeft="@drawable/contact_us_green" 
        android:drawablePadding="5dp" 
        android:gravity="center" 
        android:padding="8dp" 
        android:text="Contact Us" 
        android:textColor="@color/black" /> 

       <TextView 
        android:id="@+id/textviewone" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_marginBottom="10dp" 
        android:layout_marginLeft="15dp" 
        android:layout_marginRight="15dp" 
        android:gravity="center" 
        android:textColor="@color/black" 
        android:textColorLink="#80000000" 
        android:textSize="13sp" /> 

      </LinearLayout> 
     </RelativeLayout> 
    </ScrollView> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/snackbarCoordinatorLayout" 
     android:layout_width="match_parent" 

     android:layout_height="match_parent" 
     > 

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

    <ProgressBar 
     android:id="@+id/progressBar" 
     style="?android:attr/android:progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:visibility="gone" /> 
</FrameLayout> 

Câu hỏi: -

Khi bàn phím mở ra sau đó liên hệ với chúng button và văn bản mà là ở dưới cùng của màn hình ẩn trên đằng sau bố cục trung tâm. Tôi muốn nó không nên được ẩn, trên màn hình bàn phím mở nên được di chuyển và liên hệ với chúng tôi button nên ở phía dưới.

On mở bàn phím nó trông giống như: -

enter image description here

+0

bạn không có mã trên github hoặc bitbucket để chơi với nó? :-) Chỉ cần hoạt động này với tất cả các tài nguyên. – piotrek1543

Trả lời

0

trong scrollview của bạn thêm android: isScrollContainer = "false" thuộc tính

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:isScrollContainer="false"> 

</ScrollView> 
+0

Không hoạt động .. xem dưới vẫn đang ẩn. –

0

Chỉ cần một đường duy nhất để được bổ sung ...

Thêm android:windowSoftInputMode="stateHidden|adjustPan" vào hoạt động bắt buộc của tệp kê khai của bạn.

+0

Không hoạt động với tôi –

0

Vấn đề ở đây là CardView của bạn là android:layout_centerInParent="true"LinearLayout của bạn chứa nội dung "liên hệ với chúng tôi" là android:layout_alignParentBottom="true".

Tôi sẽ suy nghĩ lại bố cục của bạn, hơi lộn xộn, nhưng có thể bạn có thể thay thế android:layout_alignParentBottom="true" trong LinearLayout bằng android:layout_below="@+id/media_card_view".

+0

'android: layout_below =" @ + id/media_card_view "' không hoạt động :(. –

0

Dưới đây là cách bố trí của tôi:

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:weightSum="2"> 

       <ImageView 
        android:id="@+id/login_image" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:background="@android:color/holo_blue_bright"/> 

       <View 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:background="@android:color/darker_gray"/> 

      </LinearLayout> 


      <android.support.v7.widget.CardView 
       android:id="@+id/media_card_view" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:layout_marginLeft="24dp" 
       android:layout_marginRight="24dp" 
       card_view:cardBackgroundColor="@android:color/white" 
       card_view:cardCornerRadius="5dp" 
       card_view:cardElevation="4dp" 
       > 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 

        > 

        <ImageView 
         android:id="@+id/logoImageView" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:background="@android:color/darker_gray" 
         android:padding="15dp" 
         /> 

        <EditText 
         android:id="@+id/usertext" 
         android:layout_width="match_parent" 
         android:layout_height="40dp" 
         android:layout_below="@id/logoImageView" 
         android:layout_marginLeft="20dp" 
         android:layout_marginRight="20dp" 
         android:layout_marginTop="20dp" 
         android:background="@android:drawable/editbox_background" 
         android:hint="User ID" 
         android:maxLength="50" 
         android:padding="10dp" 
         android:singleLine="true" 
         android:textColorHint="@color/colorPrimaryDark" 
         android:textSize="16sp"/> 


        <FrameLayout 
         android:id="@+id/passwordLayout" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_below="@id/usertext" 
         android:layout_marginTop="8dp" 
         android:orientation="horizontal"> 

         <EditText 
          android:id="@+id/passtext" 
          android:layout_width="match_parent" 
          android:layout_height="40dp" 
          android:layout_marginLeft="20dp" 
          android:layout_marginRight="20dp" 
          android:background="@android:drawable/editbox_background" 
          android:fontFamily="sans-serif" 
          android:hint="Password" 
          android:inputType="textPassword" 
          android:maxLength="50" 
          android:padding="10dp" 
          android:singleLine="true" 
          android:textColorHint="@color/colorPrimaryDark" 
          android:textSize="16sp"/> 

         <ImageView 
          android:id="@+id/passwordeye" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_gravity="right|center_vertical" 
          android:layout_marginRight="25dp" 
          android:padding="8dp" 
          android:src="@android:drawable/ic_menu_edit"/> 

        </FrameLayout> 

        <LinearLayout 
         android:id="@+id/termsLayout" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_below="@id/passwordLayout" 
         android:layout_marginLeft="15dp" 
         android:layout_marginRight="20dp" 
         android:layout_marginTop="15dp" 
         android:gravity="center" 
         android:orientation="horizontal"> 


         <ImageView 
          android:id="@+id/check_box" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:padding="5dp" 
          android:src="@android:drawable/checkbox_on_background"/> 

         <TextView 
          android:id="@+id/terms_and_cond" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="5dp" 
          android:textColor="@android:color/black" 
          android:textColorLink="#80000000" 
          android:textSize="13sp"/> 
        </LinearLayout> 

        <View 
         android:id="@+id/lineView" 
         android:layout_width="match_parent" 
         android:layout_height="1dp" 
         android:layout_below="@id/termsLayout" 
         android:layout_marginTop="15dp" 
         android:background="@android:color/darker_gray"/> 

        <LinearLayout 
         android:id="@+id/newuser_login_layout" 
         android:layout_width="match_parent" 
         android:layout_height="50dp" 
         android:layout_below="@id/lineView" 
         android:background="@android:color/darker_gray" 
         android:orientation="horizontal"> 


         <TextView 
          android:id="@+id/newUserButton" 
          android:layout_width="0dp" 
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:gravity="center" 
          android:text="New User ?" 
          android:textColorHint="@android:color/darker_gray" 
          android:textSize="17sp"/> 

         <TextView 
          android:id="@+id/loginbutton" 
          android:layout_width="0dp" 
          android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:gravity="center" 
          android:text="Login" 
          android:textColor="@android:color/white" 
          android:textSize="17sp"/> 

        </LinearLayout> 
       </RelativeLayout> 
      </android.support.v7.widget.CardView> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignBottom="@id/media_card_view" 
       android:orientation="vertical" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:gravity="center_horizontal" 
       android:layout_below="@+id/media_card_view"> 

       <TextView 
        android:id="@+id/textView" 
        android:layout_width="wrap_content" 
        android:layout_height="35dp" 
        android:layout_centerHorizontal="true" 
        android:layout_marginBottom="15dp" 
        android:drawableLeft="@android:drawable/sym_contact_card" 
        android:drawablePadding="5dp" 
        android:padding="8dp" 
        android:text="Contact Us" 
        android:textColor="@android:color/black" 
        android:layout_gravity="center"/> 


       <TextView 
        android:id="@+id/textviewone" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_marginBottom="10dp" 
        android:layout_marginLeft="15dp" 
        android:layout_marginRight="15dp" 
        android:gravity="center_horizontal" 
        android:text="Copyright by piotrek1543 @2016" 
        android:textColor="@android:color/black" 
        android:textColorLink="#80000000" 
        android:textSize="13sp"/> 
      </LinearLayout> 
     </RelativeLayout> 
    </ScrollView> 


    <ProgressBar 
     android:id="@+id/progressBar" 
     style="?android:attr/android:progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:visibility="gone"/> 

</FrameLayout> 

Sau đây là cách có vẻ trước khi mở bàn phím

và sau:

Trước hết, mở của bạn AndroidManifest và trong phần LoginActivity bạn đặt dòng này:

 android:windowSoftInputMode="stateVisible|adjustResize"> 

Sau đó Activity biểu hiện của bạn sẽ giống như thế:

<activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar" 
     android:windowSoftInputMode="stateVisible|adjustResize"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 

      <category android:name="android.intent.category.LAUNCHER"/> 
     </intent-filter> 
    </activity> 

Sau đó sửa đổi LinearLayout của bạn với các trường textoneviewtextview1 như sau:

 <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@id/media_card_view" 
      android:orientation="vertical" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" 
      android:gravity="center_horizontal" 
      android:layout_below="@+id/media_card_view"> 

      <TextView 
       android:id="@+id/textView" 
       android:layout_width="wrap_content" 
       android:layout_height="35dp" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="15dp" 
       android:drawableLeft="@android:drawable/sym_contact_card" 
       android:drawablePadding="5dp" 
       android:padding="8dp" 
       android:text="Contact Us" 
       android:textColor="@android:color/black" 
       android:layout_gravity="center"/> 


      <TextView 
       android:id="@+id/textviewone" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="10dp" 
       android:layout_marginLeft="15dp" 
       android:layout_marginRight="15dp" 
       android:gravity="center_horizontal" 
       android:text="Copyright by piotrek1543 @2016" 
       android:textColor="@android:color/black" 
       android:textColorLink="#80000000" 
       android:textSize="13sp"/> 
     </LinearLayout> 

Hy vọng nó sẽ giúp

EDIT: Nếu bạn muốn để lại BottomSheetStyle của LinearLayout của bạn, bạn có thể sử dụng mã này:

 <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignBottom="@id/media_card_view" 
      android:orientation="vertical" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" 
      android:gravity="center_horizontal|bottom" 
      app:layout_behavior="@string/bottom_sheet_behavior" 
      > 

      <TextView 
       android:id="@+id/textView" 
       android:layout_width="wrap_content" 
       android:layout_height="35dp" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="45dp" 
       android:layout_marginBottom="15dp" 
       android:drawableLeft="@android:drawable/sym_contact_card" 
       android:drawablePadding="5dp" 
       android:padding="8dp" 
       android:text="Contact Us" 
       android:textColor="@android:color/black" 
       android:gravity="center" 
       android:layout_gravity="center"/> 


      <TextView 
       android:id="@+id/textviewone" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="10dp" 
       android:layout_marginLeft="15dp" 
       android:layout_marginRight="15dp" 
       android:gravity="center_horizontal" 
       android:text="Copyright by piotrek1543 @2016" 
       android:textColor="@android:color/black" 
       android:textColorLink="#80000000" 
       android:textSize="13sp"/> 
     </LinearLayout> 

nên nó sẽ trông giống như:

nhưng sau bạn mở bàn phím của bạn, bạn sẽ thấy

của bạn "Liên hệ với chúng tôi" sẽ được ẩn đằng sau CardView. Nếu bạn muốn có cả hai số TextView, hãy suy nghĩ về kích thước giảm của media_card_view. Đối với tôi, nó quá lớn để có thể nhìn thấy cả hai chế độ xem.

0

Bạn chỉ cần thêm vài dòng trong mã của bạn

Manifest File:

<activity 
     android:name=".activities.LoginActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" 
     android:windowSoftInputMode="stateHidden|adjustResize" /> 

Nếu bạn đã thiết lập nền sau đó vấn đề với chức năng cuộn sau đó thiết lập programatically nền như dưới đây

getWindow().setBackgroundDrawableResource(R.drawable.app_bg) ; 
0

Vui lòng kiểm tra điều này. Tôi không chắc nó sẽ giúp ích hay không.

ScrollView view = (ScrollView)findViewById(R.id.scrollView); 
view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); 
view.setFocusable(true); 
view.setFocusableInTouchMode(true); 
view.setOnTouchListener(new View.OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     v.requestFocusFromTouch(); 
     return false; 
    } 
}); 
0

tôi sẽ cố gắng đưa android:layout_below="@id/media_card_view" trong LinearLayout chứa Liên hệ chúng tôi nút và loại bỏ android:layout_alignParentBottom="true" từ nó.

Bạn cũng có thể đặt android:layout_height="wrap_content" trong RelativeLayout chính và có thể xóa CoordinatorLayout nếu nó không được sử dụng trong bố cục đó.

Hy vọng điều đó sẽ giúp;)

Các vấn đề liên quan