简体   繁体   中英

All controls in my app are locked with the left side of the screen

All the textviews and seekbars that I dragged into the android screen in the Android ADK seem to be locked to the left side of the screen by default:
在此处输入图片说明

This is the xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <TextView
        android:id="@+id/freqIndxTextView_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/freqIndxTextView_string" />
    . 
    .
    .
    .
    .
    </LinearLayout>

I am supposing the problem is that I have not understood how Linearlayout works. I can move the textviews and seekbars up and down, but their left side seem to be stuck to the left edge of the screen. How do I remove this feature? Is it possible to drag and drop controls on the IDE like we can do in Visual C++?

Try to use margin in the xml, like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <TextView
        android:id="@+id/freqIndxTextView_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:text="@string/freqIndxTextView_string" />
    </LinearLayout>

Here is instruction for you. Hope it helps.:) http://android4beginners.com/2013/07/lesson-2-2-how-to-use-margins-and-paddings-in-android-layout/

Either add padding to the LinearLayout, or change the gravity to center

android:paddingLeft="16dp"

Or

android:gravity="center"

As @QuantumTiger wrote, you can use

android:paddingLeft="16dp"

You can use too

android:margingLeft="16dp"

There is a little difference between them.

Anyway, you can find much more information here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM