2014-02-12 71 views
0

我希望圖像和按鈕顯示在底部,現在它只是浮動在屏幕中間,我不喜歡那樣我是否改變它,使其出現在屏幕的底部?按鈕的尺寸是多少?如何設置圖像和按鈕在Android中使用XML顯示在底部

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".HelpActivity" > 

<TextView 
    android:id="@+id/txtBox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignRight="@+id/imageView1" 
    android:text="Connect 4 is a two-player game in which the players take turns dropping colour discs from the top into a seven-column, six-row vertically suspended grid. The aim is to get four in a row horizontally, vertically or diagonally and the first player to reach four in a row wins the game. " 
    android:textColor="#ffffff" 
    android:textSize="22dip" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/txtBox" 
    android:src="@drawable/connect4" /> 

<Button 
    android:id="@+id/btnBack" 
    android:layout_width="48dp" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/imageView1" 
    android:layout_alignLeft="@+id/txtBox" 
    android:layout_toLeftOf="@+id/imageView1" 
    android:text="Back" /> 

+0

發佈您的完整xml,我們可以看到您的產品 – codeMagic

+0

好的我會這麼做 – user3299420

+0

僅供參考:您可以點擊相應的旁邊的複選標記來接受答案 – codeMagic

回答

0

我想要的形象和按鈕,底部

使用android:layout_alignParentBottom="true"似乎有權把他們在layout的底部。對於你的ImageView你有android:layout_below="@+id/txtBox",所以它會把它放在TextView以下。如果你想要它在屏幕的右側,然後使用android:layout_alignParentRight="true"。如果您要將Button置於ImageView的左側,請使用android:layout_alignToLeftOf="@id/imageView1"

所以這會是這樣的

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".HelpActivity" > 

<TextView 
    android:id="@+id/txtBox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignRight="@+id/imageView1" 
    android:text="Connect 4 is a two-player game in which the players take turns dropping colour discs from the top into a seven-column, six-row vertically suspended grid. The aim is to get four in a row horizontally, vertically or diagonally and the first player to reach four in a row wins the game. " 
    android:textColor="#ffffff" 
    android:textSize="22dip" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true" 
    android:src="@drawable/connect4" /> 

<Button 
    android:id="@+id/btnBack" 
    android:layout_width="48dp" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@+id/imageView1" 
    android:layout_alignParentBottom="true" 
    android:text="Back" /> 
</RelativeLayout> 

什麼是按鈕大小合適的?

這完全取決於您,您的應用程序以及您的用戶期望/喜歡的內容。要知道,硬編碼的寬度和高度尺寸可能很難讓它們在不同的屏幕上看起來很相似。

相關問題