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

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

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

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Android

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

XAML

XAML(Extensible Application Markup Language)はWPF、Silverlight、Windows PhoneそしてWindows Store appsでユーザーインターフェースを定義するために使われるXML言語です。

Xamarin

Xamarin(ザマリン)は、iPhoneなどのiOSやAndroidで動作し、C# 言語を用いてアプリを開発できるクロスプラットフォーム開発環境です。Xamarin Studioと C# 言語を用いて、 iOS と Android の両方の開発を行うことができます。

Q&A

解決済

1回答

911閲覧

LinearLayout内のオブジェクトが重なってしまいます。

karin10

総合スコア34

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Android

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

XAML

XAML(Extensible Application Markup Language)はWPF、Silverlight、Windows PhoneそしてWindows Store appsでユーザーインターフェースを定義するために使われるXML言語です。

Xamarin

Xamarin(ザマリン)は、iPhoneなどのiOSやAndroidで動作し、C# 言語を用いてアプリを開発できるクロスプラットフォーム開発環境です。Xamarin Studioと C# 言語を用いて、 iOS と Android の両方の開発を行うことができます。

1グッド

0クリップ

投稿2022/10/06 09:33

編集2022/10/07 01:40

前提

1つ目のLinearLayout内にAppbarとToolbarを書いて、2つ目のLinearLayout内にButtonを書いております。
理由としては、Appbarは画面上部に表示させて、Buttonは画面下部に表示させたいからです。

それぞれのHeightについて、
Appbar:固定
Toolbar:全体のHeight - (AppbarのHeight + ButtonのHeight)
Button:ボタン数が状況によって変化するので、それに合わせて変化します。
(ButtonはLinearLayoutの中に入れていおります。)

実現したいこと

AppbarのHeightとButtonのHeightに合わせてToolbar(タブ)がHeightを調節して表示できるようにしたいです。
表示順は上から、Appbar、Toolbar、Buttonになります。
イメージ説明

発生している問題・エラーメッセージ

ToolbarのHeightをmatch_parentにしているため、画面下部に設定しているボタンと被ってしまいます。

該当のソースコード

xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.coordinatorlayout.widget.CoordinatorLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 xmlns:tools="http://schemas.android.com/tools" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 android:orientation="vertical"> 9 <LinearLayout 10 android:id="@+id/linearLayoutGuide" 11 android:orientation="vertical" 12 android:layout_width="match_parent" 13 android:layout_height="match_parent" 14 android:layout_gravity="right" 15 android:padding="5dp" 16 android:background="@drawable/border_left"> 17 <com.google.android.material.appbar.AppBarLayout 18 android:layout_width="match_parent" 19 android:layout_height="wrap_content" 20 android:theme="@style/AppTheme.AppBarOverlay" 21 app:expanded="false"> 22 <androidx.appcompat.widget.Toolbar 23 android:id="@+id/toolbar" 24 android:layout_width="match_parent" 25 android:layout_height="46dp" 26 android:background="@drawable/border_bottom" 27 android:theme="@style/AppTheme.Toolbar" 28 app:titleTextColor="@color/normalTextLight"> 29 </androidx.appcompat.widget.Toolbar> 30 </com.google.android.material.appbar.AppBarLayout> 31 <LinearLayout 32 android:id="@+id/linearLayoutGuide" 33 android:orientation="horizontal" 34 android:layout_width="match_parent" 35 android:layout_height="match_parent" 36 android:padding="5dp" 37 android:background="@drawable/border_left"> 38 39 </LinearLayout> 40 </LinearLayout> 41 <LinearLayout 42 android:id="@+id/linearLayout1" 43 android:orientation="vertical" 44 android:layout_width="match_parent" 45 android:layout_height="45dp" 46 android:layout_gravity="bottom"> 47 <Button 48 android:text="Button" 49 android:layout_width="78dp" 50 android:layout_height="48dp" 51 android:id="@+id/button1" 52 android:layout_gravity="bottom"/> 53 <Button 54 android:text="Button" 55 android:layout_width="78dp" 56 android:layout_height="48dp" 57 android:id="@+id/button1" 58 android:layout_gravity="bottom"/> 59 </LinearLayout> 60</androidx.coordinatorlayout.widget.CoordinatorLayout>

試したこと

Buttonを同じLinearLayoutに入れたりしましたが、Buttonが範囲外になってしまうか、被ってしまいます。

補足情報(FW/ツールのバージョンなど)

Microsoft Visual Studio 2019 Version 16.11.19
Microsoft .NET Framework Version 4.8.04084
MonoAndroid, Version=v9.0

takezoux2👍を押しています

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

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

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

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

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

jimbe

2022/10/06 18:39 編集

xml はエラーがありますし、使用されているリソースも分かりません、言及されていない textview があったり、 match_height という謎のワード、 CoordinatorLayout の必要は無さそうですし…。 基本どのような画面になって、どのような場合にどのように変化させたいのか、言葉では無く手書きでもスクショの切り貼りでも良いですので、図・絵として示して頂けますでしょうか。
karin10

2022/10/07 01:43

コメントありがとうございます。 誤記についてすみませんでした。XML修正しました。また、match_heightについてはmatch_parentの誤記です。CoordinatorLayoutについては認識できていませんでした。そもそも何なのか把握できていなかったので調べます。図も追記しましたので、分かりにくい点がありましたらご指摘お願いします。
jimbe

2022/10/07 03:40

修正追加ありがとうございます。
guest

回答1

0

ベストアンサー

AppBar の部分がどう動くべきなのか分からないのですが、 ContraintLayout で単純に並べてみました。
縦タブが簡単に出来たかも調べが付かなかったので、 RecyclerView で代用する形にしています。(RecyclerView の項目がクリックされたら contents に該当フラグメントを設定するようなイメージです。)
ボタンの増減は visibility で制御できます。

xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent"> 7 8 <com.google.android.material.appbar.AppBarLayout 9 android:id="@+id/appbar" 10 android:layout_width="0dp" 11 android:layout_height="wrap_content" 12 app:expanded="false" 13 app:layout_constraintEnd_toEndOf="parent" 14 app:layout_constraintStart_toStartOf="parent" 15 app:layout_constraintTop_toTopOf="parent"> 16 <androidx.appcompat.widget.Toolbar 17 android:id="@+id/toolbar" 18 android:layout_width="match_parent" 19 android:layout_height="46dp" /> 20 </com.google.android.material.appbar.AppBarLayout> 21 22 <androidx.recyclerview.widget.RecyclerView 23 android:id="@+id/tablist" 24 android:layout_width="wrap_content" 25 android:layout_height="0dp" 26 app:layout_constraintBottom_toTopOf="@id/button1" 27 app:layout_constraintStart_toStartOf="parent" 28 app:layout_constraintTop_toBottomOf="@id/appbar"/> 29 <LinearLayout 30 android:id="@+id/contents_container" 31 android:layout_width="0dp" 32 android:layout_height="0dp" 33 android:orientation="horizontal" 34 app:layout_constraintBottom_toTopOf="@id/button1" 35 app:layout_constraintEnd_toEndOf="parent" 36 app:layout_constraintStart_toEndOf="@id/tablist" 37 app:layout_constraintTop_toBottomOf="@id/appbar" /> 38 39 <Button 40 android:id="@+id/button1" 41 android:layout_width="0dp" 42 android:layout_height="wrap_content" 43 android:text="Button1" 44 app:layout_constraintBottom_toTopOf="@id/button2" 45 app:layout_constraintEnd_toEndOf="parent" 46 app:layout_constraintStart_toStartOf="parent" /> 47 <Button 48 android:id="@+id/button2" 49 android:layout_width="0dp" 50 android:layout_height="wrap_content" 51 android:text="Button2" 52 android:visibility="gone" 53 app:layout_constraintBottom_toBottomOf="parent" 54 app:layout_constraintEnd_toEndOf="parent" 55 app:layout_constraintStart_toStartOf="parent" /> 56</androidx.constraintlayout.widget.ConstraintLayout>

投稿2022/10/07 05:31

編集2022/10/07 05:35
jimbe

総合スコア12648

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

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

karin10

2022/10/07 08:05

ありがとうございます。 ContraintLayoutを用いることで実装できました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問