簡體   English   中英

相對於屏幕的布局Android TextView

[英]Layout Android TextView Relative to Screen

我是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-large)。 這些將放置在項目的res文件夾中。

只需給出layout_height,然后使用layout_gravity來將textview設置為水平居中或垂直居中。...

你想要這個嗎? 在此處輸入圖片說明

這是它的代碼:-

<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="sgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdf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dffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfd"
        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>

嘗試使用邊距和填充。 基本上,邊距是視圖相對於父視圖的偏移量,填充是視圖內容的偏移量。

layout_marginTop
layout_marginBottom
layout_marginLeft
layout_marginRight

layout_paddingTop
layout_paddingBottom
layout_paddingLeft
layout_paddingRight

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM