gpt4 book ai didi

android - Xamarin 控件相互堆叠

转载 作者:太空狗 更新时间:2023-10-29 13:03:16 26 4
gpt4 key购买 nike

我是 Xamarin 的新手,我在这里看到的教程如下: https://learn.microsoft.com/en-us/xamarin/android/get-started/hello-android/hello-android-quickstart?tabs=vswin

并且 axml 设计器应该将控件“捕捉”到您列出的其他控件的边框,但我的不是这样工作的。它只是将它们全部堆叠在一起。任何线索如何解决这个问题?我已经搜索了一段时间,但似乎没有其他人遇到过这个问题。

例如,它们都只是放置在 Pane 的左上角,即使“正确”放置在另一个控件的底部,它们也只是吸附到左上角。

编辑:共享 XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:minWidth="25px"
android:minHeight="25px"
tools:gridSpec="1|8|#0093eeff|K:#ee8700ff:16,l:72,l:16,r|S:#83ee00ff:16,0,l:16,56,l:16,0,r">
<TextView
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/textView1"
android:layout_toLeftOf="@id/textView1"
android:layout_toRightOf="@id/editText1" />
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/PhoneNumberText"
android:id="@+id/textView2" />
<Button
android:text="Translate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/PhoneNumberText"
android:id="@+id/TranslateButton"
android:layout_above="@id/PhoneNumberText" />
<EditText
android:layout_height="wrap_content"
android:layout_below="@id/PhoneNumberText"
android:id="@+id/PhoneNumberText"
android:layout_toLeftOf="@id/textView1"
android:layout_marginTop="0.0dp"
android:layout_marginBottom="0.0dp"
android:text="1-855-xamarin"
android:layout_width="wrap_content" />
</RelativeLayout>

最佳答案

Xamarin Controls piling on top of each other

您的 .axml 有几个错误。

在你的 textView2 中:

<TextView
...
android:id="@+id/textView1"
android:layout_toLeftOf="@id/textView1"
android:layout_toRightOf="@id/editText1" />
//I didn't find where you define the id -- editText1

请注意:循环依赖不能存在于RelativeLayout

What is the layout you want to achieve?

类似于您在上面链接中发布的图片?

enter image description here

如果是这样,您可以将布局文件修改为:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Enter a Phoneword:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/PhoneNumberText"
android:text="1-855-XAMARIN" />
<Button
android:text="Translate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TranslateButton" />
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TranslatedPhoneWord" />
</LinearLayout>

关于android - Xamarin 控件相互堆叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52358467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com