在imageview和线性布局顶部的按钮

时间:2015-06-27 13:51:21

标签: android android-layout 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"
tools:context="package">


<LinearLayout

    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_weight="3">


    <ImageView

        android:layout_height="wrap_content"
        android:id="@+id/imageView3"
        android:layout_gravity="center_horizontal"
        android:background="#AAAAAA"
        android:src="@drawable/write"
        android:layout_width="match_parent"
        android:layout_weight="1" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button2"
        android:layout_gravity="center_horizontal"
   />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_gravity="center_horizontal"
        android:layout_weight="2" />

</LinearLayout>

我尝试使用这个XML进行编码,问题是按钮没有呈现在按钮和线性布局之上,就像我想要在示例中发生的那样。有没有办法实现这个?

import smtplib
content = "Just does not work"
mail = smtplib.STMP('stmp.gmail.com', '587')
mail.ehlo()
mail.starttls()
mail.login('MyEmailaddress', 'password')
mail.sendmail('MyEmailaddress', 'ToEmailaddress', content)
mail.close()

2 个答案:

答案 0 :(得分:0)

协调员谷歌设计库中的布局是针对这种类型而设计的#34; com.android.support:design:22.2.0&#34;

答案 1 :(得分:0)

我通过肌酸想出了一个相对布局,其中按钮将使用 android:layout_centerInParent =“true”在中心设置然后我用 android:weightSum创建了一个线性布局=“2”然后我将linearLayout与imageView和另一个linearLayout平分。

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_centerVertical="true"
android:layout_height="fill_parent">


<LinearLayout
    android:layout_below="@+id/app_bar"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:weightSum="2"
    android:layout_height="fill_parent">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView3"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_weight="1"
        android:background="#DDF43F" />

<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">


</LinearLayout>

</LinearLayout>
<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:background="@drawable/button_custom_login"/>
</RelativeLayout>
相关问题