2021. 9. 29. 10:13ㆍ모바일/Android_Java
[Android] ScrollView 안에 View가 Scrollview를 가득 채우지 못할때
android:fillViewport="true"
위 코드를 추가한다.
remember that android:layout_height=”fill_parent”
means “set the height to the height of the parent.” This is obviously not what you want when using a ScrollView
. After all, the ScrollView
would become useless if its content was always as tall as itself. To work around this, you need to use the ScrollView attribute called android:fillViewport
. When set to true, this attribute causes the scroll view’s child to expand to the height of the ScrollView
if needed. When the child is taller than the ScrollView
, the attribute has no effect.
+ adjustResize로 에딧텍스트를 키보드와 함께 올릴 때 이미지 찌그러지는 문제점
The full solution involves a few key points
- Use
RelativeLayout
, so thatViews
can be setup to overlap one another - Align the
EditText
with the bottom of theWindows
usingandroid:layout_alignParentBottom="true"
- Use
android:windowSoftInputMode="adjustResize"
in your manifest, so that the bottom of theWindow
changes when the keyboard pops up (as you mentioned) - Put the
ImageView
inside aScrollView
so that theImageView
can be larger than theWindow
, and disable scrolling on theScrollView
by usingScrollView#setEnabled(false)
Here is the layout file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.so3.MainActivity">
<ScrollView
android:id="@+id/scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/stickfigures"/>
</ScrollView>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/holo_blue_bright"
android:text="Please enter text"
android:textSize="40sp"
android:gravity="center_horizontal"/>
</RelativeLayout>
Here is my Activity
package com.so3;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ScrollView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ScrollView sv = (ScrollView)findViewById(R.id.scroll);
sv.setEnabled(false);
}
}
My AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.so3" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.so3.MainActivity"
android:windowSoftInputMode="adjustResize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
출처 : https://stackoverflow.com/questions/10211338/view-inside-scrollview-doesnt-take-all-place
'모바일 > Android_Java' 카테고리의 다른 글
[Android] WebView shouldOverrideUrlLoading 한글 깨짐 (0) | 2021.10.18 |
---|---|
[Android] CompositeDisposable , Disposable (0) | 2021.10.15 |
[Android] RadioGroup, RadioButton 관계 (0) | 2021.09.28 |
[Android] layout select color change (레이아웃 선택 컬러 변경) (0) | 2021.07.23 |
[Android] Cdata tag 종류 (0) | 2021.06.30 |