简体   繁体   English

如何在Android中以编程方式更改布局高度

[英]How to change layout height programmatically in Android

I try to change RelativeLayout height programmatically. 我尝试以编程方式更改RelativeLayout的高度。 I try to explain my problem: In my activity.xml file, I have header layout(top position) and I also have one layout in botton position. 我尝试解释一下我的问题:在我的activity.xml文件中,我具有标题布局(顶部位置),并且在波顿位置也具有一种布局。 With a click, I try to change botton position layout's height(full screen - Top layout height). 通过单击,我尝试更改botton位置布局的高度(全屏-顶部布局高度)。

Here is activity.xml code: 这是activity.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" >

<RelativeLayout
    android:id="@+id/movies_title_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/headerimage" >

    <ImageView
        android:id="@+id/gomoviewlist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="12dp"
        android:background="@drawable/slide_menu_image" />
</RelativeLayout>

<ImageView
    android:id="@+id/play_trailer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="@drawable/play_trailer" />

<RelativeLayout
    android:id="@+id/popaplayout"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/movie_info_shadow" >

    <TextView
        android:id="@+id/movies_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="18dp"
        android:layout_marginTop="14dp"
        android:text="TextView"
        android:textColor="#ffffff"
        android:textSize="22dp" />

    <TextView
        android:id="@+id/category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/movies_title"
        android:layout_below="@+id/movies_title"
        android:layout_marginTop="16dp"
        android:text="TextView"
        android:textColor="#ffffff"
        android:textSize="20dp" />

    <TextView
        android:id="@+id/descraption"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/category"
        android:layout_marginLeft="18dp"
        android:layout_marginTop="5dp"
        android:text="TextView"
        android:textColor="#ffffff"
        android:textSize="20dp" />
</RelativeLayout>

Here is Java code: 这是Java代码:

popaplayout.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            RelativeLayout.LayoutParams layout_description = new RelativeLayout.LayoutParams
                    (RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT-movies_header_layout.getWidth()  );

            popaplayout.setLayoutParams(layout_description);

        }
    });

popaplayout is the layout witch I try to change it's height. popaplayout是我尝试更改其高度的布局巫婆。

How can I solve my problem? 我该如何解决我的问题?

Add this to your onClickListener: 将此添加到您的onClickListener:

((RelativeLayout.LayoutParams)popaplayout.getLayoutParams()).addRule(RelativeLayout.BELOW, R.id.movies_title_layout);

This will make the view's top the same as the header's bottom 这将使视图的顶部与标题的底部相同

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

相关问题 在Android中以编程方式更改线性布局高度 - change linear layout height programmatically in Android 如何将高度布局更改为动画(以编程方式) - how to change a height layout as animation (programmatically) 如何根据布局高度以编程方式更改视图高度 - how to change a view height programmatically based on a layout height 以编程方式更改布局高度,ClassCastException? - programmatically change layout height, ClassCastException? 以编程方式更改约束布局中的高度? - Programmatically change height in constraint layout? 如何在Android中以编程方式更改位图的高度和宽度? - How to change bitmap height and width programmatically in android? 如何以编程方式更改Android ListView的布局边距 - how to change the layout margin for an Android ListView Programmatically 如何在 Android 中以编程方式更改小部件布局背景 - How to change widget layout background programmatically in Android Android:如何以编程方式将表格布局高度平均划分为表格行 - Android: How to equally divide the table layout height to table rows in programmatically 如何在android中以编程方式获取相对-线性布局的宽度和高度? - How to get programmatically width and height of Relative - Linear layout in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM