티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Difference between adjustResize and adjustPan in android?
안드로이드에서 adjustResize와 adjustPan의 차이점은 무엇인가요?
문제 내용
I tried to write a code which is used to re-size the UI components when soft-keyboard appears. When I use adjustResize, it res-size the UI components and at the same time adjustPan gave me same output. I want to know the difference between them and when to use each component? Which one(adjustPan or adjustResize) is good for resizing UI?
소프트 키보드가 나타날 때 UI 구성 요소의 크기를 조정하는 코드를 작성했습니다. adjustResize를 사용하면 UI 구성 요소의 크기가 조정되고, adjustPan을 사용하면 같은 결과가 나타납니다. 둘의 차이점과 각 구성 요소를 언제 사용해야 할까요? 어느 것이 UI 크기 조정에 더 좋은가요?
Here is my xml:
다음은 제 xml입니다:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<EditText
android:id="@+id/editText5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:text="My Button" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
and the menifest file:
그리고 메니페스트 파일입니다:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.adjustscroll"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.adjustscroll.MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
높은 점수를 받은 Solution
From the Android Developer Site link
안드로이드 개발자 사이트 링크에서 확인할 수 있는 내용은 다음과 같습니다.
"adjustResize"
The activity's main window is always resized to make room for the soft keyboard on screen.
"adjustPan"
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
"adjustResize"
화면에서 소프트 키보드가 나타날 때 항상 액티비티 윈도우의 메인 윈도우 크기를 조정합니다.
"adjustPan"
화면에서 소프트 키보드가 나타날 때 액티비티 윈도우의 메인 윈도우 크기를 조정하지 않습니다. 대신 윈도우의 내용이 자동으로 팬되어 현재 포커스가 키보드에 가려지지 않고 사용자가 입력한 내용을 항상 볼 수 있도록합니다. 사용자가 윈도우의 가려진 부분에 접근하고 상호 작용하기 위해 소프트 키보드를 닫아야하는 경우가 발생할 수 있으므로 일반적으로 조정하는 것보다는 조정하지 않는 것이 덜 선호됩니다.
according to your comment, use following in your activity manifest
당신의 의견에 따르면, 매니페스트에서 다음을 사용하십시오.
<activity android:windowSoftInputMode="adjustResize"> </activity>
가장 최근 달린 Solution
Thanks @Nadeem for the inspiration.
@Nadeem 님에게 영감을 받았습니다.
This may demonstrate the difference more intuitively.
이것이 차이를 더 직관적으로 보여줄 수 있습니다.
When the keyboard is not showing:
키보드가 나타나지 않은 경우:
When the soft keyboard shows
소프트 키보드가 표시될 때
On my simulator, adjustUnspecified has the same result with adjustPan.
내 시뮬레이터에서 adjustUnspecified는 adjustPan과 동일한 결과를 나타냅니다.
Here is the layout xml file:
레이아웃 xml 파일은 다음과 같습니다:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- This layout takes all the reset of the screen -->
<LinearLayout
android:id="@+id/layout_colors"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/et_input_field"
>
<!-- Divide the layout into 3 different colors -->
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/holo_red_light"
/>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/holo_green_light"
/>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/holo_blue_light"
/>
</LinearLayout>
<EditText
android:id="@+id/et_input_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:imeOptions="actionDone"
app:layout_constraintBottom_toBottomOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
출처 : https://stackoverflow.com/questions/17410499/difference-between-adjustresize-and-adjustpan-in-android
'개발 > 안드로이드' 카테고리의 다른 글
안드로이드 뷰에서 발생하는 "Error parsing XML: unbound prefix" 오류 수정하기 (0) | 2023.02.19 |
---|---|
android.content.res.Resources$NotFoundException: String resource ID #0x0 오류 수정하기 (0) | 2023.02.19 |
안드로이드 인플레이트(inflate)의 의미 (0) | 2023.02.18 |
안드로이드: 액션바의 커스텀 레이아웃에서 왼쪽 여백 제거하기 (0) | 2023.02.18 |
안드로이드 알림 대화상자에서 사용자 정의 리스트 뷰 표시하기 (0) | 2023.02.18 |