2014-09-17 2 views
0
/*This is my mainActivity.class*/ 

    public class MainActivity extends ActionBarActivity{  

     attachFragments(); 

     } 

private void attachFragments() { 

     CustomFragment chatFragment=new CustomFragment(); 
     FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
     transaction.add(R.id.first, chatFragment); 
     transaction.commit(); 

    } 

} 



/*mainActivity.xml*/ 



    <?xml version="1.0" encoding="utf-8"?> 
     < com.prospus.poms.layout.CustomSlidingLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/mainLayout" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent"> 
    <RelativeLayout 
     android:id="@+id/first" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" > 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/second" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" > 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/third" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" > 
    </RelativeLayout> 

    </com.prospus.poms.layout.CustomSlidingLayout> 


CustomSlidingLayout.java 


public class CustomSlidingLayout extends LinearLayout { 

private static final int SLIDING_DURATION = 500; 

private static final int QUERY_INTERVAL = 16; 

int mainLayoutWidth; 

private View menuRight; 
private View content; 

private enum MenuState { 
    HIDING, HIDDEN, SHOWING, SHOWN, 
}; 

private int contentXOffset; 
private int menuWidth; 
private int rightMenuOffset; 

private MenuState currentMenuState = MenuState.HIDDEN; 

private Scroller menuScroller = new Scroller(this.getContext(), 
     new EaseInInterpolator()); 

private Runnable rightMenuRunnable = new MenuRightRunnable(); 
private Handler menuHandler = new Handler(); 

public CustomSlidingLayout(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public CustomSlidingLayout(Context context) { 
    super(context); 
} 

@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
    mainLayoutWidth = MeasureSpec.getSize(widthMeasureSpec); 
    menuWidth=mainLayoutWidth; 
} 

@Override 
protected void onAttachedToWindow() { 
    super.onAttachedToWindow(); 

    content = this.getChildAt(0); 
    menuRight = getChildAt(1); 
    menuRight.setVisibility(View.GONE); 
} 

@Override 
protected void onLayout(boolean changed, int left, int top, int right, 
     int bottom) { 
    if (changed) { 
     LayoutParams contentLayoutParams = (LayoutParams) content 
       .getLayoutParams(); 
     contentLayoutParams.height = this.getHeight(); 
     contentLayoutParams.width = this.getWidth(); 
     LayoutParams menuLayoutParams = (LayoutParams) menuRight.getLayoutParams(); 
     menuLayoutParams.height = this.getHeight(); 
     menuLayoutParams.width = this.getWidth(); 

    } 

    menuRight.layout(right - rightMenuOffset, top, right - rightMenuOffset 
      + menuWidth, bottom); 
    content.layout(left, top, right, bottom); 
} 

@SuppressLint("NewApi") 

public void toggleRightMenu() { 
    if (currentMenuState == MenuState.HIDING 
      || currentMenuState == MenuState.SHOWING) 
     return; 

    switch (currentMenuState) { 
    case HIDDEN: 
     currentMenuState = MenuState.SHOWING; 
     menuRight.setVisibility(View.VISIBLE); 
     menuScroller.startScroll(0, 0, 
       -menuRight.getLayoutParams().width, 0, SLIDING_DURATION); 

     contentXOffset = 0; 
     rightMenuOffset = 0; 
     invalidate(); 
     break; 
    case SHOWN: 
     currentMenuState = MenuState.HIDING; 
     menuScroller.startScroll(contentXOffset, 0, -contentXOffset, 0, 
       SLIDING_DURATION); 
     break; 
    default: 
     break; 
    } 


    menuHandler.postDelayed(rightMenuRunnable, QUERY_INTERVAL); 

    this.invalidate(); 
} 

protected class MenuRightRunnable implements Runnable { 
    @Override 
    public void run() { 
     boolean isScrolling = menuScroller.computeScrollOffset(); 
     adjustRightContentPosition(isScrolling); 
    } 
} 

@SuppressLint("NewApi") 

private void adjustRightContentPosition(boolean isScrolling) { 
    int scrollerXOffset = menuScroller.getCurrX(); 

    menuRight.offsetLeftAndRight(scrollerXOffset - contentXOffset); 
    rightMenuOffset += (contentXOffset-scrollerXOffset); 
    contentXOffset = scrollerXOffset; 
    this.invalidate(); 

    if (isScrolling) 
     menuHandler.postDelayed(rightMenuRunnable, QUERY_INTERVAL); 
    else 
     this.onMenuSlidingComplete(); 
} 

private void onMenuSlidingComplete() { 
    switch (currentMenuState) { 
    case SHOWING: 
     currentMenuState = MenuState.SHOWN; 
     break; 
    case HIDING: 
     currentMenuState = MenuState.HIDDEN; 
     break; 
    default: 
     return; 
    } 
} 
protected class EaseInInterpolator implements Interpolator { 
    @Override 
    public float getInterpolation(float t) { 
     return (float) Math.pow(t - 1, 5) + 1; 
    } 

} 

public boolean isMenuShown() { 
    return currentMenuState == MenuState.SHOWN; 
} 

}EditText получить шкуру, когда клавиатура открыта

/*I am using this customlayout in main activity and in each sub layout attching a fragment. */ 




/* Layout file of fragment: */ 

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 

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

     <LinearLayout 
      android:id="@+id/title_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <include layout="@layout/header_layout" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/main" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/bottomLayout" 
      android:layout_below="@id/title_layout" 
      android:orientation="horizontal" > 

      <ListView 
       android:id="@+id/chatList" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:cacheColorHint="@android:color/transparent" 
       android:divider="@android:color/black" 
       android:fadeScrollbars="false" 
       android:fadingEdge="none" 
       android:isScrollContainer="false" 
       android:listSelector="@android:color/transparent" 
       android:overScrollMode="never" 
       android:scrollbarStyle="insideInset" 
       android:scrollbars="vertical" 
       android:stackFromBottom="true" 
       android:transcriptMode="alwaysScroll" > 
      </ListView> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@id/bottomLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:background="@color/title_background" 
      android:orientation="horizontal" > 

      <RelativeLayout 
       android:id="@+id/upload" 
       android:layout_width="@dimen/BASE_50_DP" 
       android:layout_height="match_parent" 
       android:layout_gravity="bottom" > 

       <ImageView 
        android:id="@+id/upload_icon" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:src="@drawable/ic_launcher" /> 
      </RelativeLayout> 

      <EditText 
       android:id="@+id/chattext" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:layout_marginBottom="@dimen/BASE_5_DP" 
       android:layout_marginTop="@dimen/BASE_5_DP" 
       android:layout_weight="1" 
       android:background="@android:color/white" 
       android:maxHeight="@dimen/EditTextHeight" 
       android:minHeight="@dimen/BASE_45_DP" 
       android:padding="@dimen/BASE_5_DP" 
       android:selectAllOnFocus="true" 
       android:singleLine="false" /> 

      <RelativeLayout 
       android:layout_width="@dimen/BASE_50_DP" 
       android:layout_height="match_parent" 
       android:layout_gravity="bottom" > 

       <ImageView 
        android:id="@+id/done" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:src="@drawable/ic_launcher" /> 
      </RelativeLayout> 
     </LinearLayout> 
    </RelativeLayout> 

</ScrollView> 

kayboard скрыть EditText но когда клавиатура скрывает, EditText приходит в середине экрана. Точно противоположно требованию. Я знаю, что основной проблемой является мой собственный макет. Пожалуйста, скажите мне, что не так в этом обычном режиме. Все работает нормально, если я заменил customLayout на relativeLayoot. но я должен использовать этот макет. Пожалуйста, помогите мне.

ответ

0
<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true"> 

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

    <LinearLayout 
     android:id="@+id/title_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <include layout="@layout/header_layout" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/bottomLayout" 
     android:layout_below="@id/title_layout" 
     android:orientation="horizontal" > 

     <ListView 
      android:id="@+id/chatList" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:cacheColorHint="@android:color/transparent" 
      android:divider="@android:color/black" 
      android:fadeScrollbars="false" 
      android:fadingEdge="none" 
      android:listSelector="@android:color/transparent" 
      android:overScrollMode="never" 
      android:scrollbarStyle="insideInset" 
      android:scrollbarThumbVertical="@drawable/scrollbar_thumb" 
      android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track" 
      android:scrollbars="vertical" 
      android:stackFromBottom="true" 
      android:transcriptMode="alwaysScroll" > 
     </ListView> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@id/bottomLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="@color/title_background" 
     android:orientation="horizontal" > 

     <RelativeLayout 
      android:id="@+id/upload" 
      android:layout_width="@dimen/BASE_50_DP" 
      android:layout_height="match_parent" 
      android:layout_gravity="bottom" > 

      <ImageView 
       android:id="@+id/upload_icon" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:src="@drawable/upload_icon" /> 
     </RelativeLayout> 

     <EditText 
      android:id="@+id/chattext" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_marginBottom="@dimen/BASE_5_DP" 
      android:layout_marginTop="@dimen/BASE_5_DP" 
      android:layout_weight="1" 
      android:background="@android:color/white" 
      android:maxHeight="@dimen/EditTextHeight" 
      android:minHeight="@dimen/BASE_45_DP" 
      android:padding="@dimen/BASE_5_DP" 
      android:selectAllOnFocus="true" 
      android:singleLine="false" /> 

     <RelativeLayout 
      android:layout_width="@dimen/BASE_50_DP" 
      android:layout_height="match_parent" 
      android:layout_gravity="bottom" > 

      <ImageView 
       android:id="@+id/done" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:src="@drawable/input_done_icon" /> 
     </RelativeLayout> 
    </LinearLayout> 

</RelativeLayout> 
</ScrollView> 
+0

Используется для просмотра прокрутки с помощью windowSoftInputMethod = "AdjustResize" 1. При первом нажатии на клавиатуру скрывается текст editText. 2. При нажатии на кнопку btn keyboad исчезают, и просмотр прокрутки занимает только половину высоты экрана (слева от высоты, используемой для клавиатуры), эта область отображается в этой ситуации пустым. 3. Когда я снова нажимаю на editText, он приходит в желаемую ситуацию. Не могли бы вы дать мне решение этой проблемы? – user3289808

+0

не использовать какой-либо windowSoftInputMethod для конкретной деятельности – John

0

поставить все мнение Scrollview

<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:id="@+id/title_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <include layout="@layout/header_layout" /> 
    </LinearLayout>  
    ..... 
    </RelativeLayout> 
</ScrollView> 
+0

Когда клавиатура исчезает, прокруткаView не заполняет весь экран. область, где клавиатура появлялась, отображается пустой после исчезновения клавиатуры. пожалуйста, помогите – user3289808

+0

облако вы отправляете образец кода? проверит его. –

+0

Я отредактировал мой вопрос, пожалуйста, просмотрите его – user3289808

0

Просто обернуть все Относительное расположение внутри ScrollView.

также

ЗАМЕТЬТЕ, что Scrollview может иметь только вид 1 ребенок

, и это будет ваш внешний reletive макет.

ans указанная выше ссылка на документацию для методов scrollview, которые могут использоваться для установки различных свойств в java-файле.

Смежные вопросы