Android : 상위 하단 + 하단 여백 정렬
나는 상대적인 레이아웃을 사용했고 화면 하단에 버튼을 설정하고 싶지만 이것은 모든 것을 하단에 놓고 화면 끝 사이에 약간의 공간이 있도록 약간의 여백을두고 싶습니다. 보기 및 버튼. 그러나 내가 버튼 여백을하는 것은 어떤 이유로 2.1+에서 아무것도하지 않습니다. 상대 레이아웃에는 배경이 포함되어 있으므로 그에 대한 여백이 있습니다.
누구든지 이것에 대한 해결책을 알고 있습니까?
<?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"
android:layout_marginBottom="0dp"
android:background="@drawable/background" >
<Button
android:id="@+id/confirm_mobile_button_next"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_centerHorizontal="false"
android:layout_centerInParent="false"
android:layout_margin="15dp"
android:background="@drawable/button_shape_selector"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:text="@string/confirm_mobile_no_continue"
android:textColor="@color/white"
android:textStyle="bold" />
</RelativeLayout>
Button에 여백 대신 RelativeLayout에 패딩을 추가 할 수 있습니다 (예 : android:paddingBottom="15dp".
일반적으로 저는 항상 API 레벨 8 설정을 사용하여 Exclipse 미리보기에서 레이아웃을 테스트하고 있습니다. 이것은 ICS 및 JB를 포함한 대부분의 장치에 대해 매우 정확한 결과를 제공합니다.
당신이 할 수있는 다른 일은 View의 하단에 정렬 된 a 를 놓고 다음 RelativeLayout과 같이 사용하려는 하단 여백으로 높이를 설정하는 것입니다 (또는 단순히 값을 지정하십시오 layout_marginBottom).
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/some_image"
android:adjustViewBounds="true"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some Overlay"
android:padding="3dip"
android:gravity="center_vertical|center_horizontal"
android:layout_above="@+id/empty_view"
android:layout_marginBottom="35dip"
/>
<View
android:id = "@+id/empty_view"
android:layout_height = "30dip"
android:layout_width = "match_parent"
android:visibility="invisible"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
이 예에서는 채워 RelativeLayout을 가진 ImageView, 및 위치 결정을 TextView오버 ImageView.
Yu는 translateY 속성을 사용할 수 있습니다.
translateY="-16dp"
최종 코드
<?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"
android:layout_marginBottom="0dp"
android:background="@drawable/background">
<Button
android:id="@+id/confirm_mobile_button_next"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_centerHorizontal="false"
android:layout_centerInParent="false"
android:layout_margin="15dp"
android:background="@drawable/button_shape_selector"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:text="@string/confirm_mobile_no_continue"
android:textColor="@color/white"
android:textStyle="bold"
android:translateY="-16dp" />
</RelativeLayout>
가장 좋은 방법은 설정하는 것입니다.
<...
android:layout_alignParentBottom="true" />
그런 다음 Java 코드 뒤에 :
Button confirm_mobile_button_next = (Button)findViewById(R.id.confirm_mobile_button_next)
confirm_mobile_button_next.setTransitionY(-THE_VALUE) or setTransitionX(-THE_VALUE)
@franny zhao가 제안한 유일한 솔루션은 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/fl_layout"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_layout"
android:text="hello world"
android:layout_marginBottom="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</RelativeLayout>
다른 사용자가 제안한대로 아래쪽 정렬 된 뷰에 패딩을 추가하면 뷰 배경도 확장됩니다. 배경색이있는 경우보기가 아래쪽에 붙어있는 것처럼 보입니다. 패딩과 여백은 완전히 다르며 패딩은 뷰의 일부이지만 여백은 뷰 사이에 공간을 남깁니다.
I think the best way is to set android:layout_alignParentBottom in XML then in java code behind:
Button confirm_mobile_button_next = (Button)findViewById(R.id.confirm_mobile_button_next)
and
confirm_mobile_button_next.setTransitionY(-THE_VALUE) or setTransitionX(-THE_VALUE)
Since I stumbled upon this issue, and saw no answers fit to my situation I started thinking for half a second and resolved it by setting a negative margin on the view inside the RelativeLayout sample:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="-8dp"
android:layout_marginStart="-8dp">
</RelativeLayout>
This should prove useful to some people.
You can use a ViewGroup(for example, FrameLayout or LinearLayout) to wrap the view. Set alignParentBottom in the outside ViewGroup, then marginBottom can work in the inside View.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/fl_layout"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_layout"
android:text="hello world"
android:layout_marginBottom="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</RelativeLayout>
Try in this way :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="17dp"
android:text="Button" />
Here is another alternative. If you want to set the child's margin instead of parent's padding, you should set the value of android:layout_marginTop to double of the desired margin and then set the android:layout_centerVertical to true. Top margin is given double the desired value to compensate the bottom margin. That way you will have an equal top and bottom margin around the child view.
<Button
android:id="@+id/confirm_mobile_button_next"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_centerVertical="true"
android:layout_centerInParent="false"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="30dp"
android:background="@drawable/button_shape_selector"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:text="@string/confirm_mobile_no_continue"
android:textColor="@color/white"
android:textStyle="bold" />
It will give you the same result.
참고URL : https://stackoverflow.com/questions/13441723/android-align-parent-bottom-bottom-margin
'IT TIP' 카테고리의 다른 글
| 작은 따옴표 만 이스케이프하려면 어떻게합니까? (0) | 2020.11.20 |
|---|---|
| 매개 변수가 bash 스크립트에 제공되었는지 확인하는 방법 (0) | 2020.11.20 |
| Spring MVC : 차이점 (0) | 2020.11.20 |
| 익명 열거 형 사용 (0) | 2020.11.19 |
| Vagrant / VirtualBox / Apache2 이상한 캐시 동작 (0) | 2020.11.19 |