Note that there are some explanatory texts on larger screens.

plurals
  1. POLayout Android TextView Relative to Screen
    primarykey
    data
    text
    <p>I'm new to Android and I'm trying to place a textview in a specific area of the screen using Android. Currently, the textview covers the whole screen. I need it to be restricted to a particular central section. See the screenshot below (I need the textview's frame to be the white square):</p> <p><img src="https://i.stack.imgur.com/1KFU4.png" alt="The TextViewFrame I Require"></p> <p>Here is the code I am currently using:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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"&gt; &lt;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"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>I've tried a few things I can't get it to work, can anyone point out where I'm going wrong?</p> <p>It seems I should be using LinearLayout in order to set my views to a certain percentage of the screen, but I'm not sure if this is the correct approach?</p> <p><strong>EDIT</strong>: Though the answer I've marked as correct is essentially the right thing to do, if you are going to create specific layouts such as this you will need to create different layout files for each different screen size (generally small, medium, large and x-large). These will be placed in the res folder in your project.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload