0

我是 Android 新手,我正在尝试使用 Android 在屏幕的特定区域放置一个文本视图。目前,textview 覆盖了整个屏幕。我需要将其限制在特定的中心部分。请参阅下面的屏幕截图(我需要 textview 的框架为白色方块):

我需要的 TextViewFrame

这是我目前正在使用的代码:

    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false"
    android:background="@drawable/help"
    android:gravity="left" 
    android:layout_weight="1">

    <TextView 
        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:scrollbars = "vertical"
        android:layout_weight="0.60"
        android:textSize="14sp" 
        android:textStyle="bold" 
        android:id="@+id/text"/>

</LinearLayout>

我已经尝试了一些我无法让它工作的东西,有人能指出我哪里出错了吗?

看来我应该使用 LinearLayout 将我的视图设置为屏幕的某个百分比,但我不确定这是否是正确的方法?

编辑:虽然我标记为正确的答案本质上是正确的,但如果您要创建这样的特定布局,您将需要为每个不同的屏幕尺寸(通常是小、中、大)创建不同的布局文件和 x 大)。这些将被放置在您项目的 res 文件夹中。

4

3 回答 3

1

你想要这个,礼?在此处输入图像描述

这是它的代码:-

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

    <TextView
        android:id="@+id/text"
        android:text="sgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdf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dfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:layout_marginLeft="40dp"
        android:layout_marginTop="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginBottom="40dp"
        android:background="@drawable/ic_launcherwrweq"
        android:textSize="20sp"
        android:textStyle="bold" />

</RelativeLayout>
于 2013-10-29T13:12:56.793 回答
1

只需给出 layout_height ,然后使用 layout_gravity 将 textview 设置为水平中心或垂直中心....

于 2013-10-29T13:06:57.147 回答
1

尝试使用边距和填充。基本上,边距是视图相对于父视图的偏移量,填充是视图内容的偏移量。

layout_marginTop
layout_marginBottom
layout_marginLeft
layout_marginRight

layout_paddingTop
layout_paddingBottom
layout_paddingLeft
layout_paddingRight
于 2013-10-29T13:14:59.437 回答