2013-10-29 96 views
0

我是Android新手,我試圖使用Android在屏幕的特定區域放置文本視圖。目前,textview覆蓋整個屏幕。我需要將它限制在特定的中央部分。請參見下面的截圖(我需要的TextView的框架是白方):佈局Android TextView相對於屏幕

The TextViewFrame I Require

這是我目前使用的代碼:

<?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來將我的視圖設置爲一定比例的屏幕,但我不確定這是否是正確的方法?

編輯:雖然我已標記爲正確的答案基本上是做正確的事情,如果你要創建的具體佈局,像這樣的,你需要爲每個不同的屏幕尺寸創建不同的佈局文件(一般爲小,中,大和大)。這些將被放置在項目的res文件夾中。

+2

設置lineat佈局重心center_vertical和center_horizo​​ntal並給你的textview留下餘量。 –

+1

創建自定義文本視圖。 http://stackoverflow.com/questions/11293866/how-to-have-a-circular-textview – Hemant

回答

1

你要這個,儀式? enter image description here

這裏是它的代碼: - 使用邊距和填充

<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="sgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbv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dnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfdsgfdsgdfsfddjvjkfdnbvkfdnvkjfdvfdvdffdfd" 
     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> 
1

簡單地給layout_height比使用layout_gravity用於設置在中心TextView的水平或垂直居中....

1

嘗試。基本上,邊距是視圖與父視圖的偏移量,填充是視圖內容的偏移量。

layout_marginTop 
layout_marginBottom 
layout_marginLeft 
layout_marginRight 

layout_paddingTop 
layout_paddingBottom 
layout_paddingLeft 
layout_paddingRight