2017-05-16 9 views
4

ConstraintLayout 사용법을 배웁니다. 그리고 문제가 있습니다.ConstraintLayout 오류 : 지정된 이름과 일치하는 리소스가 없습니다.

내 activity_test.xml

<?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" 
    android:padding="@dimen/default_padding"> 

    <RelativeLayout 
     android:id="@+id/reserved_layout_search" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     app:layout_constraintBottom_toBottomOf="@id/btnScanQRCode" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@id/btnScanQRCode" 
     app:layout_constraintTop_toTopOf="parent"> 

     <EditText 
      android:id="@+id/etSearchWorker" 
      style="@style/EditTextSearch" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      /> 

     <Button 
      android:id="@+id/btnClearSearch" 
      android:layout_width="32dp" 
      android:layout_height="32dp" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:background="@drawable/ic_clear"/> 

    </RelativeLayout> 

    <Button 
     android:id="@+id/btnScanQRCode" 
     android:layout_width="@dimen/search_qr_button_size" 
     android:layout_height="@dimen/search_qr_button_size" 
     android:background="@drawable/button_qr_background" 
     android:text="@string/button_qr_text" 
     android:textColor="@color/white" 
     app:layout_constraintLeft_toRightOf="@id/reserved_layout_search" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent"/> 

    <TextView 
     android:id="@+id/tvPlanningCountInfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="8dp" 
     android:text="ddsadsas" 
     app:layout_constraintHorizontal_chainStyle="spread" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@id/tvReservedContInfo" 
     app:layout_constraintTop_toBottomOf="@id/btnScanQRCode" 
     /> 

    <TextView 
     android:id="@+id/tvReservedContInfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="dsdsadasdasad :44" 
     app:layout_constraintLeft_toRightOf="@id/tvPlanningCountInfo" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="@id/tvPlanningCountInfo" 
     /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rvReserved" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginTop="@dimen/default_padding" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@id/tvPlanningCountInfo" 
     app:layout_constraintBottom_toBottomOf="parent" 
     /> 

</android.support.constraint.ConstraintLayout> 

그리고 나는/다시/클린 프로젝트를 빌드 할 때 나는 오류 처리 : 무슨 문제가 될 수있는

/Users/ME/Documents/Projects/testApp/app/src/main/res/layout/activity_test.xml 
Error:(14, 49) No resource found that matches the given name (at 'layout_constraintBottom_toBottomOf' with value '@id/btnScanQRCode'). 
Error:(16, 46) No resource found that matches the given name (at 'layout_constraintRight_toLeftOf' with value '@id/btnScanQRCode'). 
Error:(56, 46) No resource found that matches the given name (at 'layout_constraintRight_toLeftOf' with value '@id/tvReservedContInfo'). 

? 아마이 코드를 더 최적으로 작성하는 것이 가능했을까요?

하지만 미리보기가 작동합니다 : 당신은 당신이 그것을 정의하기 전에 요소를 기반으로 제약 조건을 설정하려고 screen

답변

13

. 그래서 당신은 두 가지 방법으로이 문제를 해결하려면 다음

첫 번째 솔루션 : 교체하여 RelativeLayout의 (@ + ID/reserved_layout_search는)에 의해 ID 값을 제한 :

@id/btnScanQRCode -> @+id/btnScanQRCode 
@id/btnScanQRCode -> @+id/btnScanQRCode 
@id/tvReservedContInfo -> @+id/tvReservedContInfo 

두 번째 솔루션 : 당신의 btnScanQRCode 선언 , btnScanQRCode 및 tvReservedContInfo 위젯을 XML 파일의 RelativeLayout 앞에 추가합니다.

+0

들으! 너 나 좀 도와 줘. 따라서 당신이 @ + id를 선언 할 수 있다는 것을 알지 못했습니다. – abbath0767

2

(및 @id/tvReservedContInfo)을 (@+id/btnScanQRCode@+id/tvReservedContInfo)로 바꿉니다.

이 시도 :

<?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" 
    android:padding="@dimen/default_padding"> 

    <RelativeLayout 
     android:id="@+id/reserved_layout_search" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     app:layout_constraintBottom_toBottomOf="@+id/btnScanQRCode" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/btnScanQRCode" 
     app:layout_constraintTop_toTopOf="parent"> 

     <EditText 
      android:id="@+id/etSearchWorker" 
      style="@style/EditTextSearch" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      /> 

     <Button 
      android:id="@+id/btnClearSearch" 
      android:layout_width="32dp" 
      android:layout_height="32dp" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:background="@drawable/ic_clear"/> 

    </RelativeLayout> 

    <Button 
     android:id="@+id/btnScanQRCode" 
     android:layout_width="@dimen/search_qr_button_size" 
     android:layout_height="@dimen/search_qr_button_size" 
     android:background="@drawable/button_qr_background" 
     android:text="@string/button_qr_text" 
     android:textColor="@color/white" 
     app:layout_constraintLeft_toRightOf="@+id/reserved_layout_search" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent"/> 

    <TextView 
     android:id="@+id/tvPlanningCountInfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="8dp" 
     android:text="ddsadsas" 
     app:layout_constraintHorizontal_chainStyle="spread" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/tvReservedContInfo" 
     app:layout_constraintTop_toBottomOf="@+id/btnScanQRCode" 
     /> 

    <TextView 
     android:id="@+id/tvReservedContInfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="dsdsadasdasad :44" 
     app:layout_constraintLeft_toRightOf="@id/tvPlanningCountInfo" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="@id/tvPlanningCountInfo" 
     /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rvReserved" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginTop="@dimen/default_padding" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@id/tvPlanningCountInfo" 
     app:layout_constraintBottom_toBottomOf="parent" 
     /> 

</android.support.constraint.ConstraintLayout> 
+0

thx! 나는 당신이 묘사하는 것과 똑같이했는데 조금 더 일찍 - 정확하게 작동합니다. – abbath0767

+0

다행을 알고 있습니다 :) – FAT