XML布局重叠文本问题

发布于 2024-12-18 15:33:38 字数 3354 浏览 0 评论 0原文

我使用了relativelayout,这就是我所得到的。我无法让图像填充我想要的部分。我不知道如何解决它。我听说过一些关于使用布局权重的事情,我应该使用它吗?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
android:background="@drawable/background">


<ImageView
    android:id="@+id/imagehome"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_margin="10dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_above="@+id/tvtitle1"
    android:src="@drawable/one" />

   <TextView
        android:id="@+id/tvtitle1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"         
        android:gravity="center_vertical"
        android:text="Voted Best Dentist five years running by"
        android:textSize="16dp"
        android:textColor="#9D4F1B"
        android:layout_above="@+id/tvtitle2"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="6dp"/>


   <TextView
        android:id="@+id/tvtitle2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="The Oakland Tribune"
        android:textSize="16dp"
        android:textColor="#9D4F1B"
        android:layout_above="@+id/tvhome"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="15dp"/>

    <TextView
        android:id="@+id/tvhome"
        android:layout_width="280dp"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="     You&apos;ll be cared for by our highly trained staff of dental professionals,energized to work as a team while providing the highest quality of care for your dental health. We offer complete dentistry for the entire family at a single location.                                                           "
        android:textColor="#4C2016"
        android:textSize="15dp"
        android:layout_centerHorizontal="true"
        android:layout_above="@+id/special"
        android:layout_marginBottom="25dp" />


    <Button
        android:id="@+id/special"
        android:layout_width="120dp"
        android:layout_height="40dp"
        android:background="@drawable/cc"
        android:text="Specials"
        android:textColor="#F6E6C6"
        android:textSize="17dp"
        android:textStyle="bold"
        android:layout_centerHorizontal="true"
        android:layout_above="@+id/tvbutton"
        android:layout_marginBottom="15dp" />


    <TextView
        android:id="@+id/tvbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="App provided by Bay Area Dental Marketing"
        android:layout_centerHorizontal="true"
        android:textSize="10dp"
        android:layout_alignParentBottom="true" />



 </RelativeLayout>

在 xml 文件上

在此处输入图像描述

并在设备上

在此处输入图像描述

它变得更好了,但还没有!

I used relativelayout and here is what I've got. I can't get the image to fill the section I want. I don't know how to fix it. I've heard something about using layout weight, is that some thing I should use?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
android:background="@drawable/background">


<ImageView
    android:id="@+id/imagehome"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_margin="10dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_above="@+id/tvtitle1"
    android:src="@drawable/one" />

   <TextView
        android:id="@+id/tvtitle1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"         
        android:gravity="center_vertical"
        android:text="Voted Best Dentist five years running by"
        android:textSize="16dp"
        android:textColor="#9D4F1B"
        android:layout_above="@+id/tvtitle2"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="6dp"/>


   <TextView
        android:id="@+id/tvtitle2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="The Oakland Tribune"
        android:textSize="16dp"
        android:textColor="#9D4F1B"
        android:layout_above="@+id/tvhome"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="15dp"/>

    <TextView
        android:id="@+id/tvhome"
        android:layout_width="280dp"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="     You'll be cared for by our highly trained staff of dental professionals,energized to work as a team while providing the highest quality of care for your dental health. We offer complete dentistry for the entire family at a single location.                                                           "
        android:textColor="#4C2016"
        android:textSize="15dp"
        android:layout_centerHorizontal="true"
        android:layout_above="@+id/special"
        android:layout_marginBottom="25dp" />


    <Button
        android:id="@+id/special"
        android:layout_width="120dp"
        android:layout_height="40dp"
        android:background="@drawable/cc"
        android:text="Specials"
        android:textColor="#F6E6C6"
        android:textSize="17dp"
        android:textStyle="bold"
        android:layout_centerHorizontal="true"
        android:layout_above="@+id/tvbutton"
        android:layout_marginBottom="15dp" />


    <TextView
        android:id="@+id/tvbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="App provided by Bay Area Dental Marketing"
        android:layout_centerHorizontal="true"
        android:textSize="10dp"
        android:layout_alignParentBottom="true" />



 </RelativeLayout>

on the xml file,

enter image description here

and on the device

enter image description here

It got better but it'snot there yet!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

末が日狂欢 2024-12-25 15:33:38

不确定您有多少灵活性,但最好的解决方案是从背景中删除文本和图像并将它们添加为视图。正如您所经历的,除非每个部分都作为视图添加,否则几乎不可能保证它在所有设备上看起来都正确。

Not sure how much flexibility you have but the best solution would be to remove the text and image from the background and add them as views instead. As you have experienced unless each piece is added as a view it is nearly impossible to guarantee it will look correct on all devices.

圈圈圆圆圈圈 2024-12-25 15:33:38

当使用多种屏幕尺寸时,我发现最佳实践是(a)使用 rel="nofollow">LinearLayout ,或者 (b) 在<一href="http://developer.android.com/reference/android/widget/ScrollView.html" rel="nofollow">ScrollView。

When working with multiple screen sizes, I have found it best practice to either (a) use RelativeLayout, or (b) set a LinearLayout inside a ScrollView.

舞袖。长 2024-12-25 15:33:38

使用RelativeLayout,这样您就不必指定像素。

或者,如果您要为某一特定手机执行此操作,请在 Eclipse 的 XML 设计器中选择相应的屏幕尺寸。然而,使用RelativeLayout保证它可以在所有手机上运行

Use RelativeLayout so you won't have to specify the pixels.

Alternativley if you are doing that for one particular phone select corresponding screen size in the XML designer in Eclipse. Yet, using RelativeLayout guarantees it will work on all the phones

长安忆 2024-12-25 15:33:38

即使使用上面建议的答案,您仍然可能在不同尺寸的屏幕上遇到问题。我能想到的最佳解决方案是为背景和前景创建单独的图像资源,然后添加以前景图像作为源的图像视图。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background" >
<!-- This method makes this layout redundant, dont need this anymore 
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="23dip"
    android:layout_marginRight="15dip"
    android:layout_marginTop="255dip" 
    android:orientation="vertical" >-->


<!-- put the foreground image in an imageview -->
<ImageView  android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/foregroundImage"/>


<TextView
    android:layout_width="276dp"
    android:layout_height="132dp"
    android:textSize="15dp"
    android:gravity="center_vertical"
    android:text="some text"
    android:textColor="#4C2016"/>

<Button
    android:id="@+id/special"
    android:layout_width="131dp"
    android:layout_height="40dp"
    android:background="@drawable/cc"
    android:layout_marginTop="20dip"
    android:layout_marginLeft="75dip"
    android:textSize="17dp"
    android:textStyle="bold"
    android:text="Specials"
    android:textColor="#F6E6C6" />
</LinearLayout>

Even using the suggested answers above you may still run into problem on different size screens. The best solution I can think of is to create separate image resources for the background and foreground then add an image view with the foreground image as the source.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background" >
<!-- This method makes this layout redundant, dont need this anymore 
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="23dip"
    android:layout_marginRight="15dip"
    android:layout_marginTop="255dip" 
    android:orientation="vertical" >-->


<!-- put the foreground image in an imageview -->
<ImageView  android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/foregroundImage"/>


<TextView
    android:layout_width="276dp"
    android:layout_height="132dp"
    android:textSize="15dp"
    android:gravity="center_vertical"
    android:text="some text"
    android:textColor="#4C2016"/>

<Button
    android:id="@+id/special"
    android:layout_width="131dp"
    android:layout_height="40dp"
    android:background="@drawable/cc"
    android:layout_marginTop="20dip"
    android:layout_marginLeft="75dip"
    android:textSize="17dp"
    android:textStyle="bold"
    android:text="Specials"
    android:textColor="#F6E6C6" />
</LinearLayout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文