前提
LinearLayoutを新しく追加して、アプリのレイアウトを調整しようとしています。
実現したいこと
- レイアウト(xml)ファイル内で「"@+id/〇〇"」を使って制約を設定したいです。
発生している問題
- LinearLayoutの中に入れ子になったViewのIDを指定する方法がわかりません。
下記のように、squareView(入れ子になったView)をLinearLayoutの外から指定しようとするとエラーが発生してしまいます。
xml
1app:layout_constraintEnd_toEndOf="@+id/squareView" 2app:layout_constraintStart_toStartOf="@+id/squareView"
▼エラー内容
`@+id/squareView` is not a sibling in the same `ConstraintLayout`
該当のソースコード
xml
1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".FishingFirstActivity"> 8 9 <ImageView 10 android:id="@+id/background" 11 android:layout_width="match_parent" 12 android:layout_height="match_parent" 13 android:scaleType="centerCrop" 14 app:layout_constraintBottom_toBottomOf="parent" 15 app:layout_constraintEnd_toEndOf="parent" 16 app:layout_constraintStart_toStartOf="parent" 17 app:layout_constraintTop_toTopOf="parent" 18 app:srcCompat="@drawable/ocean" /> 19 20 <LinearLayout 21 android:id="@+id/linearLayout" 22 android:layout_width="match_parent" 23 android:layout_height="0dp" 24 android:orientation="vertical" 25 app:layout_constraintBottom_toBottomOf="parent" 26 app:layout_constraintEnd_toEndOf="parent" 27 app:layout_constraintStart_toStartOf="parent" 28 app:layout_constraintTop_toTopOf="parent"> 29 30 <TextView 31 android:id="@+id/titleText" 32 android:layout_width="match_parent" 33 android:layout_height="0dp" 34 android:layout_marginHorizontal="10dp" 35 android:layout_marginTop="10dp" 36 android:layout_weight="2" 37 android:autoSizeTextType="uniform" 38 android:background="#FFEB3B" 39 android:gravity="center" 40 android:paddingHorizontal="10dp" 41 android:paddingVertical="20dp" 42 android:text="@string/fishing_first_explain" 43 android:textColor="#000000" 44 android:textStyle="bold" 45 app:layout_constraintEnd_toEndOf="parent" 46 app:layout_constraintHorizontal_bias="0.0" 47 app:layout_constraintStart_toStartOf="parent" 48 app:layout_constraintTop_toTopOf="@+id/background" /> 49 50 <View 51 android:id="@+id/squareView" 52 android:layout_width="match_parent" 53 android:layout_height="0dp" 54 android:layout_marginHorizontal="40dp" 55 android:layout_marginVertical="50dp" 56 android:layout_weight="8" 57 android:background="@drawable/shape_round_corner" 58 app:layout_constraintBottom_toBottomOf="@+id/background" 59 app:layout_constraintEnd_toEndOf="parent" 60 app:layout_constraintStart_toStartOf="parent" 61 app:layout_constraintTop_toBottomOf="@+id/titleText" 62 app:layout_constraintVertical_bias="0.385" /> 63 64 </LinearLayout> 65 66 <ImageView 67 android:id="@+id/arrow" 68 android:layout_width="0dp" 69 android:layout_height="100dp" 70 android:layout_marginLeft="10dp" 71 android:layout_marginRight="100dp" 72 android:layout_marginBottom="100dp" 73 android:rotation="170" 74 app:layout_constraintEnd_toEndOf="@+id/squareView" 75 app:layout_constraintStart_toStartOf="@+id/squareView" 76 app:layout_constraintTop_toTopOf="@+id/fishingRod" 77 app:srcCompat="@drawable/yajirushi01_yuruyaka" /> 78 79 <ImageView 80 android:id="@+id/fishingRod" 81 android:layout_width="0dp" 82 android:layout_height="0dp" 83 android:layout_marginHorizontal="40dp" 84 android:rotation="0" 85 app:layout_constraintBottom_toBottomOf="@+id/squareView" 86 app:layout_constraintEnd_toEndOf="@+id/squareView" 87 app:layout_constraintStart_toStartOf="@+id/squareView" 88 app:layout_constraintTop_toTopOf="@+id/squareView" 89 app:layout_constraintVertical_bias="0.0" 90 app:srcCompat="@drawable/fishing_rod" /> 91 92 <ImageView 93 android:id="@+id/fishingRodFront" 94 android:layout_width="100dp" 95 android:layout_height="250dp" 96 android:layout_marginLeft="45dp" 97 android:layout_marginBottom="-50dp" 98 android:visibility="invisible" 99 app:layout_constraintBottom_toBottomOf="parent" 100 app:layout_constraintEnd_toEndOf="parent" 101 app:layout_constraintHorizontal_bias="0.498" 102 app:layout_constraintStart_toStartOf="parent" 103 app:srcCompat="@drawable/fishing_rod_front" 104 tools:visibility="visible" /> 105 106 <androidx.constraintlayout.widget.Guideline 107 android:id="@+id/guideline2" 108 android:layout_width="wrap_content" 109 android:layout_height="wrap_content" 110 android:orientation="vertical" 111 app:layout_constraintGuide_percent="0.5" /> 112 113 <ImageView 114 android:id="@+id/fishingLure" 115 android:layout_width="141dp" 116 android:layout_height="122dp" 117 android:rotation="90" 118 android:visibility="invisible" 119 app:layout_constraintEnd_toEndOf="parent" 120 app:layout_constraintStart_toStartOf="parent" 121 app:layout_constraintTop_toTopOf="@+id/fishingRodFront" 122 app:srcCompat="@drawable/fishing_lure" 123 tools:visibility="visible" /> 124 125 <View 126 android:id="@+id/fishingWire" 127 android:layout_width="3dp" 128 android:layout_height="10dp" 129 android:background="#AEAEAE" 130 android:visibility="invisible" 131 app:layout_constraintBottom_toTopOf="@+id/fishingRodFront" 132 app:layout_constraintEnd_toEndOf="@+id/fishingLure" 133 app:layout_constraintStart_toStartOf="@+id/fishingLure" /> 134 135</androidx.constraintlayout.widget.ConstraintLayout>
