2

これは私のレイアウトです:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/defaut_padding" >

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/defaut_padding"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@+id/photo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/picture"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitXY" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_margin="10dp"
                android:background="@drawable/watermark" />

            <ProgressBar
                android:id="@+id/bitmap_loading"
                style="?android:attr/progressBarStyleLarge"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:visibility="visible" />
        </FrameLayout>

        <FrameLayout
            android:id="@+id/user"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/photo"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="-30dp"
            android:background="@android:color/white"
            android:padding="@dimen/smallest_padding" >

            <ImageView
                android:id="@+id/user_picture"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@drawable/anonymous_user" />
        </FrameLayout>

        <TextView
            android:id="@+id/user_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/user"
            android:layout_marginLeft="@dimen/defaut_padding"
            android:layout_toRightOf="@id/user"
            android:text="@string/anonymous_user"
            android:textStyle="bold" />
    </RelativeLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
<EditText
    android:id="@+id/input_description"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="top"
    android:padding="5dp"
    android:layout_marginBottom="@dimen/defaut_padding"
    android:background="@drawable/textfield"
    android:hint="@string/description_hint"
    android:focusableInTouchMode="true"
    android:maxLines="3"
    android:scrollbars="vertical" />

<Button
    android:id="@+id/publish"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/confirm_button_selector"
    android:text="@string/confirm_button"
    android:textColor="@android:color/white"
    android:textSize="@dimen/big_text_size"
    android:textStyle="bold" />

    </FrameLayout>
</LinearLayout>

</ScrollView>

EditTextで数字を出し始めたときにソフトキーボードが表示されたらスクロールしたいです。これどうやってするの?現在、スクロールは機能しますが、キーボードがボタンの上に表示され、キーボードの上にボタンが必要です

ユーザーが EditText をクリックしたときに、スクロールを移動しようとしました。次のようにします。

mSv.scrollTo(0, mSv.getBottom());

mSv は私の ScrollView です

ただし、ユーザーが EditText を 2 回目にクリックした場合にのみ機能します。

助けてくれてありがとう。

4

3 に答える 3

2

キーボードをサイズ変更ではなくパンに変更してみてください。AndroidManifest.xmlファイルでそれを行うことができます。特定Activityの については、以下を追加します

android:windowSoftInputMode="adjustPan"

また

非表示にする場合は、次のようにします。

EditText editTextSearch = (EditText) findViewById(R.id.editTextSearch);

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextSearch.getWindowToken(), 0);

表示したい場合:

EditText editTextSearch = (EditText) findViewById(R.id.editTextSearch);
editTextSearch.requestFocus();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
于 2016-05-17T13:11:18.180 に答える
0

RelativeLayout(の外側ScrollView) を下に揃えて使用すると、使用可能な画面の下部 (キーボードの上) に固定されます。ScrollView次に、ボタンをオーバーレイしないように下マージンが必要です。

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

    <ScrollView      
        android:layout_height="match_parent"
        android:layout_width="match_parent"    
        android:orientation="vertical"      
        android:layout_marginBottom="48dp" >    

        /* Here your elements ... like EditText */

    </ScrollView>   

    <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical" 
         android:layout_marginBottom="0px"
         android:layout_alignParentBottom="true" > 

        <Button      
         android:layout_width="fill_parent"  
         android:layout_height="48dp"
         android:text="ddd" />        

    </RelativeLayout>
</RelativeLayout>

これは、(私が評価できる限り)場合にのみ機能します

  • RelativeLayout親として持つ
  • ボタンを含むScrollView以外に唯一の子として を持っているか、別のビュー (例: ) をどこかに (何らかの理由で)含んでいます。RelativeLayoutLinearLayoutScrollView

ボタンを常に下に固定したくない場合は、Pragani のリンクで説明されているように、キーボードが表示されているかどうかを検出する必要があります。

于 2013-03-20T20:31:42.033 に答える