2017-02-28 2 views
0

ソフトキーボードが表示されているときにフラグメントを調整しようとしていますが、activity_main.xmlを安定させる、つまり調整不可にします。私はこれを試してみましたが、それは動作していない:ソフトキーボードが表示されているときにフラグメントを調整し、アクティビティを安定させる

fragment.xmlを:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="15dp"> 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
     <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:scrollbars="none" 
     android:id="@+id/me_info_scroll_view" 
     > 
      <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:padding="10dp"> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/name" 
         android:textSize="18sp" 
         android:textColor="@android:color/background_dark"/> 
        <TextView 
         android:id="@+id/user_name" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_marginTop="10dp" 
         android:textStyle="bold" 
         android:textColor="@android:color/background_dark" 
         /> 
       </LinearLayout> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/address" 
         android:textSize="18sp" 
         android:textColor="@android:color/background_dark"/> 
        <TextView 
         android:id="@+id/user_address" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_marginTop="10dp" 
         android:textStyle="bold" 
         android:textColor="@android:color/background_dark" 
         /> 

       </LinearLayout> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/home_phone" 
         android:textSize="18sp" 
         android:textColor="@android:color/background_dark"/> 
        <TextView 
         android:id="@+id/user_home_phone" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_marginTop="10dp" 
         android:textStyle="bold" 
         android:textColor="@android:color/background_dark" 
         /> 

       </LinearLayout> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/mobile_phone" 
         android:textSize="18sp" 
         android:textColor="@android:color/background_dark"/> 
        <TextView 
         android:id="@+id/user_mobile_phone" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_marginTop="10dp" 
         android:textStyle="bold" 
         android:textColor="@android:color/background_dark" 
         /> 

       </LinearLayout> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/work_phone" 
         android:textSize="18sp" 
         android:textColor="@android:color/background_dark"/> 
        <TextView 
         android:id="@+id/user_work_phone" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_marginTop="10dp" 
         android:textStyle="bold" 
         android:textColor="@android:color/background_dark" 
         /> 

       </LinearLayout> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/email" 
         android:textSize="18sp" 
         android:textColor="@android:color/background_dark"/> 
        <TextView 
         android:id="@+id/user_email" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_marginTop="10dp" 
         android:textStyle="bold" 
         android:textColor="@android:color/background_dark" 
         /> 

       </LinearLayout> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/birth_date" 
         android:textSize="18sp" 
         android:textColor="@android:color/background_dark"/> 

        <TextView 
         android:id="@+id/user_birth_date" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_marginTop="10dp" 
         android:textStyle="bold" 
         android:textColor="@android:color/background_dark" 
         /> 

       </LinearLayout> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/height" 
         android:textSize="18sp" 
         android:textColor="@android:color/background_dark"/> 
        <TextView 
         android:id="@+id/user_height" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_marginTop="10dp" 
         android:textStyle="bold" 
         android:textColor="@android:color/background_dark" 
         /> 

       </LinearLayout> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/weight" 
         android:textSize="18sp" 
         android:textColor="@android:color/background_dark"/> 
        <TextView 
         android:id="@+id/user_weight" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_marginTop="10dp" 
         android:textStyle="bold" 
         android:textColor="@android:color/background_dark" 
         /> 

       </LinearLayout> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        android:gravity="center" 
        > 
        <Button 
         android:id="@+id/me_edit" 
         android:layout_width="100dp" 
         android:layout_height="wrap_content" 
         /> 
       </LinearLayout> 
      </LinearLayout> 
     </ScrollView> 

    </LinearLayout> 

</LinearLayout> 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 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/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:focusableInTouchMode="true" 
    tools:openDrawer="start"> 

    <!-- <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" />--> 

    <!--framelayout to show other fragments--> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:background="@color/navbar_color" 
       android:orientation="horizontal" 
       > 

       <!-- android:theme="@style/AppTheme.AppBarOverlay"--> 
       <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar" 
        android:layout_width="?attr/actionBarSize" 
        android:layout_height="?attr/actionBarSize" 

        android:theme="@style/AppTheme.AppBarOverlay" /> 
       <TextView 
        android:id="@+id/tab_name" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="hello" 
        android:layout_gravity="center_vertical" 
        android:textColor="@android:color/white" 
        android:textSize="20sp" 
        android:layout_margin="10dp" 
        android:layout_weight="1"/> 

       <ImageView 
        android:id="@+id/info" 
        android:layout_width="30dp" 
        android:layout_height="30dp" 
        android:src="@drawable/info_icon" 
        android:layout_margin="8dp" 
        android:layout_gravity="center" 
        /> 
      </LinearLayout> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/view_holder" 
       android:layout_weight="1" 
       /> 
     </LinearLayout> 
    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     > 
     <ListView 
      android:id="@+id/navbar_list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:divider="@android:color/background_dark" 
      android:dividerHeight="1dp"> 
     </ListView> 
    </android.support.design.widget.NavigationView> 
</android.support.v4.widget.DrawerLayout> 

mainactivity.java

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     getWindow().requestFeature(Window.FEATURE_NO_TITLE);    
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
    WindowManager.LayoutParams.FLAG_FULLSCREEN);  
     setContentView(R.layout.activity_main); 
     //checkPermission(); 
     // context of main Activity 
     context = this; 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     appInfo = (ImageView) findViewById(R.id.info); 
     navBarListView = (ListView) findViewById(R.id.navbar_list); 
     title = (TextView) findViewById(R.id.tab_name); 
     drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
     drawer.setDrawerListener(toggle); 
     toggle.syncState(); 
     setNavigationBar(true); 
     navBarListView.setOnItemClickListener(this); 

     //onclick listener for info icon 
     appInfo.setOnClickListener(this); 

     //getting db instance or initializing db 
     emergencyDetailsDatabase = EmergencyDetailsDatabase.getDbInstance(context); 
     emergencyDetailsDatabase.openDb(); 
     if(savedInstanceState == null) 
     { 
      FragmentManager fragmentManager = getFragmentManager(); 
     Fragment fragment = new Fragment1(); 
     fragmentManager.beginTransaction().replace(R.id.view_holder,fragment,"Edit user details").commit(); 
     } 
    } 

    fragment.java 
    public class Fragment1 extends Fragment { 
    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     //getActivity().getWindow().setSoftInputMode(); //getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       //WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);  getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 
     view = inflater.inflate(R.layout.fragment, container, false);  
     return view; 
    } 

androidmanifest.xml

入力キーボードが表示されたときにフラグメントを調整し、フラグメントのボタンをsoftInputmodeに表示したいとします。マニフェスト(アンドロイド:windowSoftInputMode =「adjustResize」)ソフト入力モードを定義する

答えて

0

試行

<activity 
     android:name="..MainActivity" 
     android:windowSoftInputMode="adjustResize"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     </activity> 
+0

を私がしたが、すべてのレイアウトは、すなわちdrawerlayoutまで移動するまで動いているが、私はヘッダ部が一定または固定されたいです – Bharamu

関連する問題