Android 개발 에 include 컨트롤 용법 분석
6377 단어 Androidinclude 컨트롤
우 리 는 안 드 로 이 드 시스템 을 바탕 으로 하 는 응용 프로그램의 개발 은 인터페이스 디자인 이 매우 중요 하고 사용자 체험 의 좋 고 나 쁨 과 관련 이 있다 는 것 을 안다.좋 은 인터페이스 디자인 은 xml 레이아웃 으로 해결 할 수 있 는 것 이 아 닙 니 다.activity 에 컨트롤 이 매우 많 을 때 모든 레이아웃 파일 을 xml 파일 에 넣 으 면 얼마나 나 쁜 일 인지 상상 하기 쉽 습 니 다!필 자 는 자신의 경험 을 통 해 include 컨트롤 로 이 문 제 를 해결 했다.다음은 작은 예 이다.구조 만 실현 하고 코드 에 응 하지 않 는 디자인 이다.
user.xml 파일 내용 은 다음 과 같 습 니 다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" : " />
<EditText
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="@+id/userName"
android:hint=" "
/>
</LinearLayout>
passwd.xml 파일 내용 은 다음 과 같 습 니 다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" :" />
<EditText
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="@+id/passWd"
android:hint=" "
/>
</LinearLayout>
login.xml 파일 내용 은 다음 과 같 습 니 다.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:layout_width="80dp"
android:layout_height="wrap_content"
android:id="@+id/bt"
android:hint=" "
/>
<Button
android:layout_width="80dp"
android:layout_height="wrap_content"
android:id="@+id/reset"
android:layout_toRightOf="@id/bt"
android:hint=" "
/>
</RelativeLayout>
main.xml 파일 내용 은 다음 과 같 습 니 다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/head"
android:layout_alignParentTop="true">
<include
android:layout_width="fill_parent"
layout="@layout/user">
</include>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/middle"
android:layout_below="@id/head"
android:layout_alignParentLeft="true">
<include
android:layout_width="fill_parent"
layout="@layout/passwd">
</include>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/foot"
android:layout_below="@id/middle"
android:layout_alignParentRight="true">
<include
android:layout_width="fill_parent"
layout="@layout/login">
</include>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
프로그램 실행 결 과 는 다음 과 같 습 니 다.main.xml 에 이렇게 쓰 면:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<include
android:layout_width="fill_parent"
layout="@layout/user">
</include>
<include
android:layout_width="fill_parent"
layout="@layout/passwd">
</include>
<include
android:layout_width="fill_parent"
layout="@layout/login">
</include>
</LinearLayout>
그러면 이 상황 에서 의 운행 결 과 는 다음 과 같다.실행 결과 가 예상 과 맞지 않 는 것 이 분명 합 니 다.다음 네 개의 컨트롤 이 나 오지 않 습 니 다.왜 일 까요?틀림없이 모두 가 실험 을 할 때,틀림없이 이 문제 에 부 딪 힌 적 이 있 을 것 이다.)
사실 관건 적 인 부분 은 main 파일 에서 각 xml 에 대한 레이아웃 입 니 다.해당 하 는 레이아웃 이 없 으 면 결 과 는 매우 비참 합 니 다.여러분 은 제 코드 에 따라 해당 하 는 레이아웃 을 수정 하고 main 에서 레이아웃 의 중요성 을 느 낄 수 있 습 니 다!
더 많은 안 드 로 이 드 관련 내용 에 관심 이 있 는 독자 들 은 본 사이트 의 주 제 를 볼 수 있다.
본 고 에서 말 한 것 이 여러분 의 안 드 로 이 드 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Bitrise에서 배포 어플리케이션 설정 테스트하기이 글은 Bitrise 광고 달력의 23일째 글입니다. 자체 또는 당사 등에서 Bitrise 구축 서비스를 사용합니다. 그나저나 며칠 전 Bitrise User Group Meetup #3에서 아래 슬라이드를 발표했...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.