Android 선형 레이아웃-요소를 하단에 유지하는 방법?
I가 가지고 TextView
있는 I가 사용하고있는 가로 활동의 하단에 고정 할 LinearLayout
수직으로 배열 요소.
android:gravity="bottom"
텍스트보기를 설정 했지만 여전히 LinearLayout
원하지 않는 작업 의 마지막 요소 바로 아래에있는 것을 좋아합니다 .
어떤 제안?
업데이트 : 나는 여전히이 질문에 대해 찬성표를 얻습니다. 이것은 여전히 받아 들여지는 대답이고 제가 잘못 대답했다고 생각합니다. 최고의 정보를 제공한다는 정신으로이 답변을 업데이트하기로 결정했습니다.
현대의 Android에서는 ConstraintLayout
이것을 사용 합니다. 더 성능이 좋고 간단합니다.
<ConstraintLayout>
<View
android:id="@+id/view1"
...other attributes elided... />
<View
android:id="@id/view2"
app:layout_constraintTop_toBottomOf="@id/view1" />
...other attributes elided... />
...etc for other views that should be aligned top to bottom...
<TextView
app:layout_constraintBottom_toBottomOf="parent" />
ConstraintLayout을 사용하지 않으려면 확장 뷰와 함께 LinearLayout을 사용하는 것이 추가 공간을 차지하는 것을 처리하는 간단하고 훌륭한 방법입니다 (@Matthew Wills의 답변 참조). 하단보기 위에보기의 배경을 확장하지 않으려면 보이지 않는보기를 추가하여 공간을 차지할 수 있습니다.
내가 원래 준 대답은 효과가 있지만 비효율적입니다. 비 효율성은 단일 최상위 레이아웃의 경우 큰 문제가 아닐 수 있지만 ListView
또는 에서 끔찍한 구현이 될 수 RecyclerView
있으며 대략 동일한 수준의 더 나은 방법이 있기 때문에 수행 할 이유가 없습니다. 더 간단하지는 않더라도 노력과 복잡성이 있습니다.
LinearLayout에서 TextView를 꺼내고 나서 LinearLayout과 TextView를 RelativeLayout 안에 넣습니다. android:layout_alignParentBottom="true"
TextView에 속성 을 추가하십시오 . 위의 속성을 제외한 모든 네임 스페이스 및 기타 속성이 제거 된 경우 :
<RelativeLayout>
<LinearLayout>
<!-- All your other elements in here -->
</LinearLayout>
<TextView
android:layout_alignParentBottom="true" />
</RelativeLayout>
설정하여 나머지 공간을 채우기 위해 상위 뷰 중 하나를 확장해야 android:layout_weight="1"
합니다. 그러면 마지막 뷰가 아래쪽으로 내려갑니다.
다음은 내가 의미하는 바에 대한 간략한 스케치입니다.
<LinearLayout android:orientation="vertical">
<View/>
<View android:layout_weight="1"/>
<View/>
<View android:id="@+id/bottom"/>
</LinearLayout>
각각의 자식 뷰 높이는 "wrap_content"
있고 나머지는 모두입니다 "fill_parent"
.
나는 그것이 완벽한 해결책이 될 것이라고 생각합니다.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Other views -->
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<!-- Target view below -->
<View
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
매개 변수 중력을 textview가 아닌 Linear Layout에서 맨 아래에 배치해야 합니다. 이렇게 :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom|end">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Something"/>
</LinearLayout>
1 단계 : 선형 레이아웃 내부에 두 개의보기 만들기
Step 2 : First view must set to android:layout_weight="1"
Step 3 : Second view will automatically putted downwards
<LinearLayout
android:id="@+id/botton_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/btn_health_advice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
You can also use
android:layout_gravity="bottom"
for your textview
DO LIKE THIS
<LinearLayout
android:id="@+id/LinearLayouts02"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom|end">
<TextView
android:id="@+id/texts1"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="2"
android:text="@string/forgotpass"
android:padding="7dp"
android:gravity="bottom|center_horizontal"
android:paddingLeft="10dp"
android:layout_marginBottom="30dp"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="50dp"
android:fontFamily="sans-serif-condensed"
android:textColor="@color/colorAccent"
android:textStyle="bold"
android:textSize="16sp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
/>
</LinearLayout>
try this
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewProfileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
'IT TIP' 카테고리의 다른 글
LIKE를 사용한 Spring JPA @Query (0) | 2020.10.27 |
---|---|
600851475143에 대한 "정수 숫자가 너무 큽니다"오류 메시지 (0) | 2020.10.27 |
iOS7에서 UISearchBar의 배경색을 변경하는 방법 (0) | 2020.10.27 |
역 색인이있는 부분 문자열 (0) | 2020.10.27 |
Android에서 MMS 데이터를 읽는 방법? (0) | 2020.10.27 |