質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

1回答

557閲覧

LinearLayout内のViewのIDをレイアウト(xml)ファイル内で取得したい

m-mega

総合スコア56

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2022/09/27 06:14

編集2022/09/29 09:53

前提

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>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

jimbe

2022/09/27 10:10

コードのマークダウン(```) で kotlin と書かれている所はコードの言語を書く所です。 ですのでレイアウトファイルは xml です。
guest

回答1

0

LinearLayoutの中に入れ子になったViewのIDを指定する方法がわかりません。

@+id/squareView is not a sibling in the same ConstraintLayout

@+id/squareView は同じ ConstraintLayout の兄弟ではありません」by Google翻訳

出来ないということでしょう。

また、 LinerLayout 内のビューに ConstraintLayout の制約を書いていますが、無意味です。
LinerLayout 内のビューは LinerLayout によってのみ制御され、 ConstraintLayout の制約を書いても無視されるだけです。

投稿2022/09/27 10:14

編集2022/09/27 10:16
jimbe

総合スコア12646

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m-mega

2022/09/29 09:54

ご回答いただきありがとうございます。 やはり、できないのですね。承知しました。何か別の方法でレイアウトを整えることができないか検討してみます。
jimbe

2022/09/29 10:56 編集

各ビューのどの(上下左右)辺とどの辺とがどう関係するようにしたいのかがハッキリすればこちらでも試してみますが。 (drawable を除いてレイアウトを見ましたが、やはり画像が無いとどんなのかさっぱり分かりませんでした^^;)
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問