[英]How to change layout height programmatically in Android
我嘗試以編程方式更改RelativeLayout的高度。 我嘗試解釋一下我的問題:在我的activity.xml
文件中,我具有標題布局(頂部位置),並且在波頓位置也具有一種布局。 通過單擊,我嘗試更改botton位置布局的高度(全屏-頂部布局高度)。
這是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>
這是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是我嘗試更改其高度的布局巫婆。
我該如何解決我的問題?
將此添加到您的onClickListener:
((RelativeLayout.LayoutParams)popaplayout.getLayoutParams()).addRule(RelativeLayout.BELOW, R.id.movies_title_layout);
這將使視圖的頂部與標題的底部相同
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.