小编Vik*_*war的帖子

动态更改相对布局宽度和高度

嗨我在LinearLayout中使用以下布局结构

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </TableRow>

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/tv1"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:paddingLeft="10dp"
            android:textColor="#000" />

        <TextView
            android:id="@+id/tv2"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:gravity="right"
            android:paddingRight="10dp"
            android:textColor="#000" />
    </TableRow>
</TableLayout>

<ImageView
    android:id="@+id/img1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" />

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="320px"
    android:layout_height="320px"
    android:gravity="center" >
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

并且想要从java文件中动态设置相对布局的宽度和高度,而不是在xml文件中将其设置为320px但不能这样做,因为我将限制仅限于纵向模式,因此方向更改不是问题.可以使用match_parent在全屏幕上设置相对布局,但我必须在屏幕上放置另一个视图,这样才有可能,或者我必须以另一种方式实现它...

android android-layout

16
推荐指数
3
解决办法
7万
查看次数

android中是否有可能在方向变化时动态调整画布宽度和高度

我在画布上使用了背景图像,并尝试在设备方向更改时相应地调整其大小,有人可以建议我在 android 中可以在方向更改时重新调整画布尺寸。

android

5
推荐指数
1
解决办法
2181
查看次数

禁用方向更改

可能重复:
如何在Android中禁用方向更改?

我希望在以任何方向(纵向或横向)打开画布后禁用方向更改,但是在横向模式下打开画布并更改设备方向时,我遇到问题,方向未被禁用.

这是代码.

public void onConfigurationChanged(Configuration newConfig) {

  super.onConfigurationChanged(newConfig);
  this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

}
Run Code Online (Sandbox Code Playgroud)

android

0
推荐指数
1
解决办法
4238
查看次数

标签 统计

android ×3

android-layout ×1