【发布时间】:2021-07-25 12:19:21
【问题描述】:
我想在 View(代表一个矩形)中放置一个 LinearLayout,以便在这个 Layout 中放置更多元素。不幸的是,这不起作用,当我将 LinearLayout 或其他元素放入 View 时,它无法识别它们。
我在 Visual Studio Community 2019 中使用 Xamarin.Android(仅 Android,不是 iOS)。
这是 XML 代码。 @drawable/rounded 只是一个 .xml 文件,它使视图成为一个带圆角的矩形。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:background="#ff74a8a7"
android:orientation="vertical">
<!--Header-->
<TextView
android:text="MyTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:gravity="center"
android:id="@+id/txtTitle"
android:textColor="#ff2f5858"
android:textStyle="bold" />
<!--View-->
<View
android:layout_width="300dp"
android:layout_height="450dp"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:background="@drawable/rounded"
android:backgroundTint="#ff38817a" >
<!--Here should the next LinearLayout go, e.g.: (does not work!-->
<LinearLayout>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--Elements inside this LinearLayout, e.g. a text and a button-->
</LinearLayout>
</View>
</LinearLayout>
我们将不胜感激如何解决这个问题!
【问题讨论】:
-
能否请您提供您正在创建的布局,以便我们帮助您弄清楚发生了什么?
-
@Cheesebaron 我在主帖中添加了 XML 代码,感谢您的帮助!
标签: c# android xamarin xamarin.android android-view