android Imageview顶部和底部

时间:2014-08-29 06:06:34

标签: android android-layout

我正在尝试获得一个将ImageView锚定到 top 的布局,ImageView锚定到 bottom 并且填充中间

LinearLayout

LinearLayout(或者我可能想要使用ScrollView)需要扩展以填充空间,具体取决于分辨率,屏幕尺寸等...

我尝试了fill_parentwrap_content等的组合..但无法将其锚定到底部

有什么想法吗?

编辑:布局代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background2"
android:background="#EEEDEB"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
         android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="174px"
        android:src="@drawable/sodexotop" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:background="#ffffff"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp">

<Button
    android:id="@+id/button4"
    android:layout_width="420px"
    android:layout_height="99px"
    android:layout_marginLeft="20sp"
    android:layout_marginRight="20sp"
    android:background="@drawable/butt1"
    android:onClick="clk_raynes"
    android:text="sitebutton"
    android:layout_marginTop="10dp"
    android:textColor="#000000"
    android:textSize="50px" />


    <Button
        android:id="@+id/rutlishbtn"
        android:layout_width="420px"
    android:layout_height="99px"
    android:layout_marginLeft="20sp"
    android:layout_marginRight="20sp"
    android:layout_marginTop="6dp"
        android:background="@drawable/butt1"
        android:onClick="clk_rutlish"
        android:text="Site2"
        android:textColor="#000000"
        android:textSize="50px" />


    <Button
        android:id="@+id/harrisbtn"
        android:layout_width="420px"
    android:layout_height="99px"
    android:layout_marginLeft="20sp"
    android:layout_marginRight="20sp"
    android:layout_marginTop="6dp"
        android:background="@drawable/butt1"
        android:onClick="clk_harris"
        android:text="Site3"
        android:textColor="#000000"
        android:textSize="50px" />

            <Button
                android:id="@+id/button3"
                android:layout_width="420px"
    android:layout_height="99px"
    android:layout_marginLeft="20sp"
    android:layout_marginRight="20sp"
    android:layout_marginTop="6dp"
                android:background="@drawable/butt1"
                android:onClick="clk_ricards"
                android:text="Site4"
                android:textColor="#000000"
                android:textSize="50px" />
            <Button
                android:id="@+id/button10"
                android:layout_width="420px"
    android:layout_height="99px"
    android:layout_marginLeft="20sp"
    android:layout_marginRight="20sp"
    android:layout_marginTop="6dp"
                android:background="@drawable/butt1"
                android:onClick="clk_btn10"
                android:text="Site5"
                android:textColor="#000000"
                android:textSize="50px" />

            <Button
                android:id="@+id/button11"
                android:layout_width="420px"
    android:layout_height="99px"
    android:layout_marginLeft="20sp"
    android:layout_marginRight="20sp"
    android:layout_marginTop="6dp"
                android:background="@drawable/butt1"
                android:onClick="clk_btn11"
                android:text="Site6"
                android:textColor="#000000"
                android:textSize="50px" />

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

           <Button
            android:id="@+id/picbtn3"

            android:layout_marginTop="6dp"
            android:layout_marginBottom="190px"

            android:text="³"
            android:textColor="#000000"
            android:textSize="30sp"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/butt1"
            android:onClick="qrbtn" />

        </LinearLayout>
        <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="174px"
        android:src="@drawable/sodexobottom" />
        </LinearLayout>

4 个答案:

答案 0 :(得分:0)

您可以像这样设置布局文件:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:background="@drawable/bg_card"
            android:padding="16dp">
            <ImageView
                android:id="@+id/topImage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"/>            
            <LinearLayout
                android:id="@+id/yourContent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/topImage"
                android:layout_above="@+id/bottomImage"
                android:layout_marginTop="4dp"
                android:orientation="vertical">
            </LinearLayout>
            <ImageView
                android:id="@+id/bottomImage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"/>
        </RelativeLayout>

</ScrollView>

答案 1 :(得分:0)

最初有三个线性布局,并设置了重量参数。在第一个和最后一个布局中使用ImageView。根据您的要求使用中间布局。

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

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:src="@drawable/abc_ab_bottom_solid_dark_holo" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:layout_weight = "4" >

</LinearLayout>

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/abc_ab_bottom_solid_dark_holo" />

</LinearLayout>

答案 2 :(得分:0)

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/background2"
      android:background="#EEEDEB"
      android:layout_width="match_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" >
    <ImageView
     android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="174dp"
    android:src="@drawable/sodexotop" />

     <ScrollView
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:layout_weight="1" >

    <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:gravity="center_horizontal"
       android:orientation="vertical"
       android:background="#ffffff"
       android:layout_marginLeft="15dp"
       android:layout_marginRight="15dp">

 <Button
android:id="@+id/button4"
android:layout_width="420dp"
android:layout_height="99dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/butt1"
android:onClick="clk_raynes"
android:text="sitebutton"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:textSize="50sp" />


<Button
    android:id="@+id/rutlishbtn"
    android:layout_width="420dp"
android:layout_height="99dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="6dp"
    android:background="@drawable/butt1"
    android:onClick="clk_rutlish"
    android:text="Site2"
    android:textColor="#000000"
    android:textSize="50sp" />


<Button
    android:id="@+id/harrisbtn"
    android:layout_width="420dp"
android:layout_height="99dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="6dp"
    android:background="@drawable/butt1"
    android:onClick="clk_harris"
    android:text="Site3"
    android:textColor="#000000"
    android:textSize="50sp" />

        <Button
            android:id="@+id/button3"
            android:layout_width="420dp"
android:layout_height="99dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="6dp"
            android:background="@drawable/butt1"
            android:onClick="clk_ricards"
            android:text="Site4"
            android:textColor="#000000"
            android:textSize="50sp" />
        <Button
            android:id="@+id/button10"
            android:layout_width="420dp"
android:layout_height="99dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="6dp"
            android:background="@drawable/butt1"
            android:onClick="clk_btn10"
            android:text="Site5"
            android:textColor="#000000"
            android:textSize="50sp" />

        <Button
            android:id="@+id/button11"
            android:layout_width="420dp"
android:layout_height="99dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="6dp"
            android:background="@drawable/butt1"
            android:onClick="clk_btn11"
            android:text="Site6"
            android:textColor="#000000"
            android:textSize="50sp" />

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

       <Button
        android:id="@+id/picbtn3"

        android:layout_marginTop="6dp"
        android:layout_marginBottom="190dp"

        android:text="³"
        android:textColor="#000000"
        android:textSize="30sp"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:background="@drawable/butt1"
        android:onClick="qrbtn" />

    </LinearLayout>
    </ScrollView>
    <ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="174dp"
    android:src="@drawable/sodexobottom" />
    </LinearLayout>

我添加了ScrollView,如果您不需要ScrollView,那么只需设置android:layout_height="0dp"&amp; android:layout_weight="1"到您的中间LinearLayout

答案 3 :(得分:0)

请尝试这种方式,希望这有助于您解决问题。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/background2"
    android:background="#EEEDEB"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="174px"
        android:adjustViewBounds="true"
        android:src="@drawable/sodexotop" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp">

            <Button
                android:id="@+id/button4"
                android:layout_width="420px"
                android:layout_height="99px"
                android:layout_marginLeft="20sp"
                android:layout_marginRight="20sp"
                android:background="@drawable/butt1"
                android:onClick="clk_raynes"
                android:text="sitebutton"
                android:layout_marginTop="10dp"
                android:textColor="#000000"
                android:textSize="50px" />


            <Button
                android:id="@+id/rutlishbtn"
                android:layout_width="420px"
                android:layout_height="99px"
                android:layout_marginLeft="20sp"
                android:layout_marginRight="20sp"
                android:layout_marginTop="6dp"
                android:background="@drawable/butt1"
                android:onClick="clk_rutlish"
                android:text="Site2"
                android:textColor="#000000"
                android:textSize="50px" />


            <Button
                android:id="@+id/harrisbtn"
                android:layout_width="420px"
                android:layout_height="99px"
                android:layout_marginLeft="20sp"
                android:layout_marginRight="20sp"
                android:layout_marginTop="6dp"
                android:background="@drawable/butt1"
                android:onClick="clk_harris"
                android:text="Site3"
                android:textColor="#000000"
                android:textSize="50px" />

            <Button
                android:id="@+id/button3"
                android:layout_width="420px"
                android:layout_height="99px"
                android:layout_marginLeft="20sp"
                android:layout_marginRight="20sp"
                android:layout_marginTop="6dp"
                android:background="@drawable/butt1"
                android:onClick="clk_ricards"
                android:text="Site4"
                android:textColor="#000000"
                android:textSize="50px" />
            <Button
                android:id="@+id/button10"
                android:layout_width="420px"
                android:layout_height="99px"
                android:layout_marginLeft="20sp"
                android:layout_marginRight="20sp"
                android:layout_marginTop="6dp"
                android:background="@drawable/butt1"
                android:onClick="clk_btn10"
                android:text="Site5"
                android:textColor="#000000"
                android:textSize="50px" />

            <Button
                android:id="@+id/button11"
                android:layout_width="420px"
                android:layout_height="99px"
                android:layout_marginLeft="20sp"
                android:layout_marginRight="20sp"
                android:layout_marginTop="6dp"
                android:background="@drawable/butt1"
                android:onClick="clk_btn11"
                android:text="Site6"
                android:textColor="#000000"
                android:textSize="50px" />

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

            <Button
                android:id="@+id/picbtn3"

                android:layout_marginTop="6dp"
                android:layout_marginBottom="190px"

                android:text="³"
                android:textColor="#000000"
                android:textSize="30sp"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:background="@drawable/butt1"
                android:onClick="qrbtn" />

        </LinearLayout>
    </ScrollView>
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="174px"
        android:adjustViewBounds="true"
        android:src="@drawable/sodexobottom" />
</LinearLayout>
相关问题