2017-03-13 1 views
1

Android에서 새로 생겼습니다. Android 앱에서 처음으로 간단한 앱을 만들었지 만 실제 휴대 전화 또는 가상 전화에서 제약 레이아웃이 올바르게 작동하지 않습니다. 나는 레이아웃의 중심에 버튼을 놓을 생각이었고 레이아웃의 맨 위에 텍스트를 편집했지만, 나는 둘 다 오른쪽 상단 레이아웃에서 같은 위치에 있었기 때문에 텍스트를 입력하고 버튼을 누를 수 없었습니다. .
RelativeLayout을 사용하려고 시도 했으므로 ConstraintLayout에서 문제가 발생했다고 생각합니다. 제발 도와주세요!

"ConstraintsLayout for Android 1.0.1 or lower"및 "Solver For ConstraintsLayout 1.0.1 or lower"를 이미 설치했습니다. build.gradle에서 'com.android.support.constraint : constraint-layout : 1.0.1'을 (를) 추가했습니다. Android Studio 버전 2.3을 사용합니다. 그리고 여기 내 XML 코드 :제약 조건 Android Studio 레이아웃이 올바르게 작동하지 않습니다.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="my.android.myfirstapp.MainActivity"> 


<Button 
    android:id="@+id/btn_jump" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Jump Activity" 
    tools:layout_editor_absoluteX="128dp" 
    tools:layout_editor_absoluteY="269dp" /> 

<EditText 
    android:id="@+id/edt_Name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:inputType="textPersonName" 
    android:text="" 
    tools:layout_editor_absoluteX="85dp" 
    tools:layout_editor_absoluteY="62dp" /> 
</android.support.constraint.ConstraintLayout> 

그리고 여기 실행하면 내 간단한 응용 프로그램입니다 :
enter image description here

답변

2

제약 조건이 설정 정확하지 않았다 당신이에 표시된 버튼을 확실 클릭 인 경우, 아래 이미지를 보면 문제가 무엇인지 알 수 있습니다. 대개 모든 레이아웃 문제가 여기에 표시됩니다.

Layout issue

사용이 제약에 대한 문제를 해결 아래 코드.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:layout_editor_absoluteY="81dp" 
    tools:layout_editor_absoluteX="0dp"> 


    <Button 
     android:id="@+id/btn_jump" 
     android:layout_width="128dp" 
     android:layout_height="48dp" 
     android:text="Jump Activity" 
     tools:layout_constraintTop_creator="1" 
     tools:layout_constraintRight_creator="1" 
     tools:layout_constraintBottom_creator="1" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     tools:layout_constraintLeft_creator="1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <EditText 
     android:id="@+id/edt_Name" 
     android:layout_width="215dp" 
     android:layout_height="43dp" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:text="" 
     tools:layout_constraintTop_creator="1" 
     tools:layout_constraintRight_creator="1" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginTop="107dp" 
     tools:layout_constraintLeft_creator="1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintHorizontal_bias="0.502" /> 
</android.support.constraint.ConstraintLayout> 

희망이 도움이, 그것은 대답

+3

XML 코드는 안드로이드 스튜디오에 의해 생성되고, 나는 이미지와 같은 경고 나 오류가 표시되지 않았다에게 표시 할 작동합니다. 그러나 귀하의 코드가 완벽하게 실행되고 난 다음 코드 몇 줄이 제대로 작동하도록 만들었습니다. app : layout_constraintBottom_toBottomOf = "parent", app : layout_constraintRight_toRightOf = "parent", app : layout_constraintLeft_toLeftOf = "parent"app : layout_constraintTop_toTopOf = "parent"마지막으로 도움을 주셔서 감사합니다! (죄송합니다,이 주석에 코드 형식을 만드는 방법을 모르겠습니다) –

관련 문제