【问题标题】:How to fix the LinearLayout as listview item如何将 LinearLayout 修复为列表视图项
【发布时间】:2017-12-29 10:10:42
【问题描述】:

这是我第一次在这里发布一个 android 问题。如果我做错了什么,请告诉我。

我有一个列表视图,我在我的 android 项目(xamarin,c#)中使用此代码作为我的列表视图项

<FrameLayout xmlns:a="http://schemas.android.com/apk/res/android" 
              a:layout_width="match_parent"
              a:layout_height="wrap_content">
    <ImageView
        a:layout_width="wrap_content"
        a:layout_height="wrap_content"
        a:adjustViewBounds="true"
        a:id="@+id/imgRecipeView" />
    <TextView
        a:id="@+id/recipeTitle"
        a:layout_width="wrap_content"
        a:layout_height="wrap_content"
        a:layout_alignParentTop="True" a:layout_below="@id/imgRecipeView" />
</FrameLayout>

我希望这个图像视图具有它自己的全宽和全高。接下来目前我的文本视图显示在图像上。我想在图像之后显示它们(顶部的图像,底部的文本,目前它正在重叠)。

我尝试了 linearlayout 和 relativelayout ,但它没有按我想要的方式工作。

【问题讨论】:

  • LinearLayout 的哪些方面不适合你
  • @zcui93 我希望这个图像视图具有全宽作为屏幕。
  • 你的布局的父宽度是多少?全宽?
  • 是的,可用屏幕的宽度(未应用任何内容)

标签: c# android android-layout listview xamarin


【解决方案1】:

尝试使用 LinearLayoutorientation="vertical"

<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
    a:layout_width="match_parent"
    a:orientation="vertical"
    a:layout_height="wrap_content">
    <ImageView
        a:layout_width="match_parent"
        a:layout_height="wrap_content"
        a:adjustViewBounds="true"
        a:scaleType="fitXY"
        a:id="@+id/imgRecipeView" />
    <TextView
        a:id="@+id/recipeTitle"
        a:layout_width="wrap_content"
        a:layout_height="wrap_content"
        />
</LinearLayout>

输出

【讨论】:

  • 你好@Prem,有什么简单的方法可以让我编写和测试我的代码。我的意思是 Visual Studio xamarin 花费了太多时间来编译并看到一些变化。
  • 我想将图像缩放到屏幕大小。除了这个,你的代码工作正常。
  • 你试过match_parenthight @Adrian
  • @Adrian 很乐意为您提供帮助
  • @Adrian Mobile 应用程序是用编译语言编写的,因此与 HTML 不同,您只需重新加载即可查看更改。 XAML 被编译为要在设备上执行的 .NET 代码。不过,我相信 Visual Studio 应该有某种 Forms Previewer 让您大致可视化您将在屏幕上看到的内容。
猜你喜欢
  • 1970-01-01
  • 2018-07-01
  • 2018-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多