![](/img/trans.png)
[英]Android Layout Animations from bottom to top and top to bottom on ImageView click
[英]android Imageview top and bottom
我正在嘗試獲得一個布局,其中將ImageView
錨定在頂部 ,將ImageView
錨定在底部,並將LinearLayout
填充在中間
LinearLayout
(或者我可能想使用ScrollView
)需要擴展以填充空間,具體取決於分辨率,屏幕尺寸等。
我嘗試了fill_parent
, wrap_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>
您可以這樣設置布局文件:
<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>
最初具有三個線性布局,並設置了重量參數。 在第一個和最后一個布局中使用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>
試試這個:
<?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"
& android:layout_weight="1"
到中間的LinearLayout
。
嘗試這種方式,希望這將幫助您解決問題。
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.