質問

UPDATE: I've opened a new thread with my updated question here: Android - How to display 4 text views with Icons? Thank you for your answers, I'd really appreciate it if you could help me with my newer thread above.

I'm trying to display 4 text views at the bottom of the screen but I can't figure out how to that that. Every time I try to move one button it screws up the rest.

Here's what it currently looks like:

enter image description here

Here's my manuel marks as to where I want to position the buttons (Each line represents a text view item position):

enter image description here

Here's the current code, any pointers would be really great:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity" >

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:adjustViewBounds="true" >
</android.support.v4.view.ViewPager>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="124dp"
    android:layout_toRightOf="@+id/ButtonRate"
    android:text="TextView" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView1"
    android:layout_alignBottom="@+id/textView1"
    android:layout_alignRight="@+id/ButtonWallpaper"
    android:text="TextView" />

<TextView
    android:id="@+id/ButtonWallpaper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/textView2"
    android:layout_marginRight="50dp"
    android:layout_marginTop="137dp"
    android:clickable="true"
    android:onClick="setWallpaper"
    android:text="@string/set_wallpaper"
    android:textColor="@color/red" />

<TextView
    android:id="@+id/ButtonRate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/ButtonWallpaper"
    android:layout_alignBottom="@+id/ButtonWallpaper"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="50dp"
    android:clickable="true"
    android:onClick="rate"
    android:text="@string/rate_button"
    android:textColor="@color/red" />

I'm really stuck.

Thanks very much in advance, Dvir

役に立ちましたか?

解決

You need to put another relative layout after ViewPager for your textViews, and add android:layout_alignParentBottom="true" to that Layout like this:

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:adjustViewBounds="true" >
</android.support.v4.view.ViewPager>

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/ButtonRate"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignBottom="@+id/textView1"
        android:layout_alignRight="@+id/ButtonWallpaper"
        android:text="TextView" />

    <TextView
        android:id="@+id/ButtonWallpaper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView2"
        android:layout_marginRight="50dp"
        android:clickable="true"
        android:onClick="setWallpaper"
        android:text="hello" />

    <TextView
        android:id="@+id/ButtonRate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/ButtonWallpaper"
        android:layout_alignBottom="@+id/ButtonWallpaper"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="50dp"
        android:clickable="true"
        android:onClick="rate"
        android:text="hello2" />
</RelativeLayout>

Also note that I've deleted android:layout_marginTop parameters, you can adjust it, if you wish

他のヒント

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />
        </LinearLayout>

         <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

You can do something like that :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="394dp"
    android:adjustViewBounds="true" >
</android.support.v4.view.ViewPager>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/ButtonRate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="39dp"
        android:text="ButtonRate" />

    <TextView
        android:id="@+id/ButtonWallpaper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="60dp"
        android:text="ButtonWallpaper" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignBottom="@+id/textView1"
        android:layout_alignLeft="@+id/ButtonWallpaper"
        android:layout_marginLeft="22dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/ButtonRate"
        android:layout_centerVertical="true"
        android:text="TextView" />

</RelativeLayout>

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top