gpt4 book ai didi

android - 填充android布局xamarin

转载 作者:行者123 更新时间:2023-11-29 23:41:26 24 4
gpt4 key购买 nike

我在 xamarin 中遇到了 android 布局问题。如何在不重叠android xml布局的情况下填充空间?

这种布局让我很困惑。因为它不像 phpxaml。我想像这样制作布局 View :

enter image description here

我在设计窗口中使用 Nexus 6。当我在模拟器中运行调试时, View 变成这样:

enter image description here

布局重叠。我想知道如何填充 android 布局大小的空白,以便它可以(动态地)适合我的设备?

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/main_content"
android:gravity="fill_horizontal|bottom">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="610.3dp"
android:layout_weight="1"
android:gravity="center|bottom">
<TextView
android:text="Location Detail"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView9"
android:layout_marginTop="10dp"
android:gravity="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="199.3dp"
android:id="@+id/linearLayout1"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/linearLayout2">
<TextView
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/editTextLocationDetailName" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/linearLayout3"
android:layout_marginTop="5dp">
<TextView
android:text="Address"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/textView4"
android:width="100dp"
android:gravity="center|left|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/textView5"
android:gravity="center|top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/editTextLocationDetailAddress" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/linearLayout4"
android:layout_marginTop="5dp"
android:gravity="top">
<TextView
android:text="Description"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/textView6"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/textView7"
android:gravity="center|top" />
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/editTextLocationDetailDescription" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="Registered User"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView8"
android:layout_marginTop="10dp"
android:gravity="center" />
<android.support.v7.widget.RecyclerView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/recyclerViewLocationUser"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBarLocationDetail"
android:layout_marginTop="20dp" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="50dp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#ff03a9f4"
android:layout_gravity="right"
android:gravity="center">

</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

有什么我可以做的吗?提前致谢:)

最佳答案

使用此 xaml 文件并与您的文件进行比较,以便您了解自己犯了什么错误

我意识到问题在于使用 android:gravity(在第二个和第三个 LinearLayout 中)以及 android:weight 将您的布局推向顶部。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/main_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="610.3dp">
<TextView
android:text="Location Detail"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView9"
android:layout_marginTop="0dp"
android:gravity="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="199.3dp"
android:id="@+id/linearLayout1"
android:layout_marginTop="0dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/linearLayout2">
<TextView
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/editTextLocationDetailName" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/linearLayout3"
android:layout_marginTop="5dp">
<TextView
android:text="Address"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/textView4"
android:width="100dp"
android:gravity="center|left|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/textView5"
android:gravity="center|top" />
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/editTextLocationDetailAddress" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/linearLayout4"
android:layout_marginTop="5dp"
android:gravity="top">
<TextView
android:text="Description"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/textView6"
android:width="100dp"
android:gravity="left|center|top" />
<TextView
android:text=":"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/textView7"
android:gravity="center|top" />
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/editTextLocationDetailDescription" />
</LinearLayout>
</LinearLayout>
<TextView
android:text="Registered User"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView8"
android:layout_marginTop="10dp"
android:gravity="center" />
<android.support.v7.widget.RecyclerView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/recyclerViewLocationUser"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBarLocationDetail"
android:layout_marginTop="20dp" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="50dp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#ff03a9f4"
android:layout_gravity="right"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

关于android - 填充android布局xamarin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51811253/

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