Imageview上面的动作栏android

时间:2014-08-19 09:06:49

标签: android layout

我是Android开发的新手。在我的主要活动中,我想隐藏操作栏并将ImageView放在最顶层。然而,在我隐藏操作栏后,ImageView不会像操作栏仍在那里一样返回顶部。任何人都可以解释我如何将ImageView置于顶部。

<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

tools:context="com.example.bestymobile.MainActivity" 
android:orientation="vertical"
>
<ImageView
    android:id="@+id/imageView2"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:src="@drawable/bluelogo" 
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_below="@id/imageView2"
    android:gravity= "center" >
    <EditText android:id="@+id/email"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:hint="@string/email" />
    <EditText android:id="@+id/pass"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:hint="@string/password" />  
    <Button
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="@string/button_send"
        android:onClick="sendMessage" 
        />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Забыли пароль?"
        android:textSize="20sp" 
        android:layout_marginTop = "20dp"/>
</LinearLayout>

这是我的布局。所以我希望ImageView位于最顶端

1 个答案:

答案 0 :(得分:0)

首先为操作栏创建布局(actionbar.xml);

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"
    android:gravity="center|left" >

    <ImageView
        android:id="@+id/imagehome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

</LinearLayout>

然后在班级中设置此布局;

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    actionBar.setCustomView(R.layout.actionbar);

如果您不想要使用imageview操作栏删除操作栏;

getSupportActionBar().hide();

并设置&#34; top&#34;重力到你的imageview

相关问题