레이아웃에 공백 추가
나는 안드로이드 내에서 빈 줄을 만들려고합니다. 이것이 내가하고있는 일입니다.
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="\n\n"
더 나은 방법이 있는지 알고 싶습니다. 감사합니다
사용 Space
또는 View
공간의 특정 금액을 추가 할 수 있습니다. 30 개의 수직 밀도 픽셀의 경우 :
<Space
android:layout_width="1dp"
android:layout_height="30dp"/>
공간 채우기가 유연한 필요한 경우 다음 View
항목간에 사용 하십시오 LinearLayout
.
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
또는
<View
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_weight="1"/>
이것은 위젯 ( FrameLayout
대신 사용)을 제외하고 API 14 이상의 대부분의 레이아웃에서 작동합니다 .
[Space를 사용하기 위해 2014 년 9 월에 업데이트되었습니다. @Sean에게 모자 팁]
간격이 정확히 2 줄 높이 일 필요가없는 경우 다음과 같이 빈을 추가 할 수 있습니다.
<View
android:layout_width="fill_parent"
android:layout_height="30dp">
</View>
업데이트 된 답변 : API 14 이후 문서에 설명 된대로 "Space"View를 사용할 수 있습니다 .
공간은 범용 레이아웃에서 구성 요소 사이에 간격을 만드는 데 사용할 수있는 경량보기 하위 클래스입니다.
보기 당신은 배경 개 색상을 변경,하다면 필요 공간 이 아니라면.
즉, 뷰 배경을 변경해야 함을 의미합니다.
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/YOUR_BACKGROUND">
</View>
또는 공간
<Space
android:layout_width="match_parent"
android:layout_height="20dp"
/>
레이아웃 사이에 공간을 제공하는 비용 공간을 사용하는 방법입니다. 여백을 제거하면 표시되지 않습니다. 표시 할 공간 내부의 텍스트를 사용하는 것은 좋은 방법이 아닙니다. 도움이 되길 바랍니다.
<Space
android:layout_width="match_content"
android:layout_height="wrap_content"
android:layout_margin="2sp" />
<View
android:layout_width="fill_parent"
android:layout_height="30dp"
android:background="#80000000">
</View>
이 시도
layout.xml에서 :
<TextView
android:id="@+id/xxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/empty_spaces" />
strings.xml에서 :
<string name="empty_spaces">\t\t</string>
그것은 나를 위해 일했다
나는 CaspNZ의 접근 방식에 강력히 동의하지 않습니다.
우선,이 보이지 않는 뷰는 "fill_parent"이기 때문에 측정됩니다. Android는 올바른 너비를 계산합니다. 대신 작은 상수 (1dp)가 여기에 권장됩니다.
둘째,보기는 가장 빠른 속도를 위해 UI 구성 요소 사이에 빈 공간을 만드는 전용 클래스 인 더 간단한 클래스 공간으로 대체되어야합니다.
이것은 공간 이나 보기 를 사용하여 달성 할 수 있습니다 .
공간 은 가볍지 만 그다지 유연하지는 않습니다.
View 는 화면에서 직사각형 영역을 차지하며 그리기 및 이벤트 처리를 담당합니다. 보기는 더 사용자 정의 가능하며 배경을 추가하고 공간과 같은 모양을 그릴 수 있습니다.
공간 구현 :
(예 : 세로 20 개 및 가로 10 개 밀도 픽셀을위한 공간)
<Space
android:layout_width="10dp"
android:layout_height="20dp"/>
구현보기 :
(예 : 배경색을 포함하여 세로 20 개 및 가로 10 개 밀도 픽셀에 대한보기)
<View
android:layout_width="10dp"
android:layout_height="20dp"
android:background="@color/bg_color"/>
HTML 엔티티를 사용하는 문자열 형식화를위한 공간 :
 
깨지지 않는 공백을 위해.  
일반 공간을 위해.
모든 답변에 동의합니다 ...... 또한,
<TextView android:text=""
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_weight="2" />
작동해야합니다 :) TextView가 내가 가장 좋아하는 (메모리 낭비!)
내 경우에는 이전 답변이 작동하지 않았습니다. 그러나 메뉴에 빈 항목을 만들면됩니다.
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
...
<item />
...
</menu>
이 작업을 수행하는 더 좋은 방법이 있습니다. 아래 코드를 사용하고 원하는 빈 영역의 크기에 따라 변경하십시오.
<Space
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_column="0"
android:layout_row="10" />
그리드 레이아웃과 함께 사용하는 경우
android:layout_row="10" />
다음은 줄 크기로 빈 줄을 만드는 간단한 방법입니다. 여기에서 빈 줄의 크기를 조정할 수 있습니다. 이걸로 해봐.
<TextView
android:id="@id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="5dp"/>
linearlayout에 weightSum 태그를 1로 추가하고 그 아래의 해당 뷰에 대해 layout_weight를 .9로 지정하면 뷰 사이에 공간이 생깁니다. 값을 실험하여 적절한 값을 얻을 수 있습니다.
참고 URL : https://stackoverflow.com/questions/6352140/adding-blank-spaces-to-layout
'ProgramingTip' 카테고리의 다른 글
거의에서 200 개의 csv 파일을 병합하는 방법 (0) | 2020.10.25 |
---|---|
연관 배열에 항목 추가 (0) | 2020.10.25 |
하나의 실행 파일이 콘솔 및 GUI 응용 프로그램이 될 수 있습니까? (0) | 2020.10.24 |
표준 VBA 기능에 대한 "프로젝트 또는 라이브러리를 사용할 수 없음" (0) | 2020.10.24 |
프로그래밍 방식으로 클라이언트를 WCF 서비스에 연결하는 방법은 무엇입니까? (0) | 2020.10.24 |