简体   繁体   English

带有4个按钮的android的ImageLayout

[英]ImageView on of Tablelayout with 4 buttons android

I'm currently making an app where I want an imageview on top of the screen (with a gap of 10% of the screen from top) and a table under the imageview with 4 buttons in it. 我目前正在制作一个应用,希望在屏幕上方显示一个图像视图(与顶部之间的间隙为屏幕的10%),并在其中包含4个按钮的图像视图下创建一个表格。

What I have right now is: 我现在所拥有的是:

<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/testhback"
android:gravity="bottom" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="@dimen/f1"
    android:adjustViewBounds="true"
    android:src="@drawable/img1" />

<TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="@dimen/top2"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/button4"
            android:onClick="changepic2"
            android:text="Breaking Dawn" />

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/button1"
            android:layout_alignBottom="@+id/button1"
            android:layout_alignLeft="@+id/button5"
            android:layout_alignParentRight="true"
            android:onClick="changepic3"
            android:text="New Moon (2)" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button3"
            android:layout_alignParentLeft="true"
            android:onClick="changepic"
            android:text="Twilight (1)" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:onClick="changepic1"
            android:text="Eclipse (3)" />
    </TableRow>
</TableLayout>

The problem is that I've tried to set margins from the top for the table. 问题是我试图从表的顶部开始设置边距。 But on each screen it looks different, and I didn't figure out how to tell it to automatically take, let's say, 10% for top line under it, 70% for the imageview, and 20% for the table with 4 button in it at the bottom. 但是在每个屏幕上它看起来都不同,我不知道如何告诉它自动获取,比如说,下面的顶行占10%,imageview占70%,带有4个按钮的表格占20%它在底部。

You can use the LinearLayout with vertical orientation and configure the layout_weight attribute in order to make this arrangement. 您可以将LinearLayout垂直使用,并配置layout_weight属性以进行这种排列。

For more information please check here http://blog.stylingandroid.com/archives/297 and come back if the problem remains. 有关更多信息,请在此处检查http://blog.stylingandroid.com/archives/297 ,如果问题仍然存在,请回来。

Hope this helps! 希望这可以帮助!

you must use android:layout_width = 0dp, android:weightSum and android:layout_weight 您必须使用android:layout_width = 0dp,android:weightSum和android:layout_weight

that thread should help you out 线程应该可以帮助您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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