2016-06-24 3 views
-3

이 코드선형 레이아웃이 제대로 구성 요소를 표시되지

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:text="Email:" 
     android:textSize="30dp" 
     android:paddingLeft="0dp" 
     android:paddingTop="10dp"/> 

    <EditText 
     android:layout_width="150dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="4dp" 
     android:singleLine="true" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Login" 
     android:paddingTop="10dp"/> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="200dp" 
      android:layout_height="100dp" 
      android:text="Home" /> 

     <TextView 
      android:layout_width="200dp" 
      android:layout_height="200dp" 
      android:text="About" /> 

    </LinearLayout> 
</LinearLayout> 

나는 안드로이드 스튜디오에서 레이아웃을 연습 원하는 코드를 실행하는 동안 오류가 받고 있어요입니다.

enter image description here

왜 파란색 상자는 모바일 화면 밖에서 이동 않습니다 이 모바일 화면 밖에서가는 텍스트는?

enter image description here

+0

먼저 디자인을 Android에서 제작하는 방법을 배워야합니다. 어디에서나보기의 너비와 높이를 하드 코딩합니다. 필요하지 않은 경우 너비와 높이를 하드 코딩해서는 안됩니다. –

답변

1

당신은 각각의 layout_width 설정하는 자신을 볼 수 있습니다. 사용할 수있는 화면의 최대 너비가 있음을 알아야합니다. 또한, 너비를 match_parent으로 설정하면 인접한 뷰의 너비가 고정되어있는 경우에는 적절하지 않습니다. LinearLayout을 사용하는 경우 layout_weight 속성을 사용해보십시오. 놀고 실험 해보십시오. 예를 들어

:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal"> 

<TextView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="2" 
    android:paddingLeft="0dp" 
    android:paddingTop="10dp" 
    android:text="Email:" 
    android:textSize="30dp" /> 

<EditText 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="4dp" 
    android:layout_weight="2" 
    android:singleLine="true" /> 

<Button 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="2" 
    android:paddingTop="10dp" 
    android:text="Login" /> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="2" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="100dp" 
     android:text="Home" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="200dp" 
     android:text="About" /> 

</LinearLayout> 
</LinearLayout> 
+0

또한 match_parent로 시도했지만 작동하지 않습니다 – BHAGAT

+0

'match_parent'를 사용하면 안됩니다 – Marat

+0

내가 업로드 한 사진을 볼 수 있습니까 ??? – BHAGAT

2

당신은 제대로 레이아웃을 설정하지 않는 것입니다. layout weight을 설정하지 않고 parentView (LinearLayout)의 childView를 가로로 정렬했습니다. documentation on LinearLayout을 읽어야합니다. 그러나 레이아웃을 수정하려면 다른 컨테이너를 추가하여 레이아웃의 첫 번째 행을 유지하여 두 번째 행을 화면에 표시 할 수 있습니다. 현재 코드에는 한 행에있는 모든 childView가 포함되어있어 다른보기가 표시되지 않습니다. 아래 코드를 사용해보십시오.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:layout_width="100dp" 
      android:layout_height="wrap_content" 
      android:text="Email:" 
      android:textSize="30dp" 
      android:paddingLeft="0dp" 
      android:paddingTop="10dp"/> 

     <EditText 
      android:layout_width="150dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="4dp" 
      android:singleLine="true" /> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Login" 
      android:paddingTop="10dp"/> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="200dp" 
      android:layout_height="100dp" 
      android:text="Home" /> 

     <TextView 
      android:layout_width="200dp" 
      android:layout_height="200dp" 
      android:text="About" /> 

    </LinearLayout> 
</LinearLayout> 
+0

감사합니다. – BHAGAT

관련 문제