0

這是我的代碼ImageView的大小調整時,鍵盤打開

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" > 

<ImageView 
    android:id="@+id/bgImage" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentTop="true" 
    android:contentDescription="@string/todo" 
    android:scaleType="fitXY" 
    android:src="@drawable/default_wallpaper" /> 

<LinearLayout 
    android:id="@+id/mainLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/title" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/in" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@android:color/transparent" 
     android:cacheColorHint="@android:color/transparent" 
     android:divider="@android:color/transparent" 
     android:stackFromBottom="true" 
     android:transcriptMode="alwaysScroll" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:orientation="horizontal" > 

     <EditText 
      android:id="@+id/edit_text_out" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_gravity="bottom" 
      android:layout_weight="1" 
      android:inputType="none" /> 

     <Button 
      android:id="@+id/button_send" 
      android:layout_width="70dp" 
      android:layout_height="fill_parent" 
      android:text="@string/send" 
      android:textSize="15sp" 
      android:textStyle="bold" /> 
    </LinearLayout> 
</LinearLayout> 

</RelativeLayout> 

在這個時候我EditText軟鍵盤上點擊打開,但我ImageView萎縮。

我在清單文件,但通過這一點,將推動整個活動的上側用android:windowSoftInputMode="adjustPan"但我想ImageView的,因爲它是當鍵盤打開ImageView的是從底部不是從頂部切爲WhatsApp應用。

任何幫助會升值。謝謝..

回答

1

刪除父佈局(RelativeLayout)並使LinearLayout僅包含對話框,父!再加上,加android:windowSoftInputMode="stateVisible|adjustResize"AndroidManifest.xml

+0

那麼如果我刪除RelativeLayout的話,我怎樣才能把ImageView的所有控件的背景是什麼? – 2013-02-28 13:21:03

2

我也有類似的問題,其中一個自定義視圖 - ParallaxBackground - 我已經適應應該由一個ViewPager在滾動驅動的視差效果作爲背景圖片同樣的活動。

換句話說,我有一個顯示寬度比屏幕稍大的圖像,當用戶沿着ViewPager滾動時,ParallaxBackground中的圖像也滾動一點。

現在在我的情況下,我的ViewPager的Fragments中有一些EditTexts,當用戶點擊它們,導致軟鍵盤出現時,ParallaxBackground(因此,背景圖像)將重新調整大小,並且「違揹我的意願」擠壓

所以我加了一個boolean isBackground,二int S表示fixedWidthfixedHeight和不顧我查看的onMeasure()像這樣:

@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 


    if(isBackground) 
    // If this is being used as a background and is supposed to occupy the whole screen... 
    { 
        // force the View to have the specified dimensions 
     setMeasuredDimension(fixedWidth, fixedHeight); 
    } 
    // ...aply default measures... 
    else 
    { 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
    } 

} 

我知道這是不是一個「美麗」的解決方案,但是,即使我的答案是不涉及您的問題100%,你可能想嘗試擴展ImageView類和壓倒一切的onMeasure

然後,在你onCreate方法,你可以設置isBackground爲true,並給予fixedWidthfixedHeight爲您測量屏幕寬度和高度的值。

相關問題