0

我必须在活动的中心|底部水平对齐两个图像视图,并且我必须以屏幕宽度百分比(例如屏幕宽度的 10%)调整图像视图的大小。

如果我不应用调整大小,我在中心|底部有两个图像视图,但太大了;如果我应用调整大小,我只有第一个在中心;另一个消失了!

我试过使用线性布局(方向=水平)和表格布局......没有结果!

这是我使用 Tablelayout 时的活动 XML:

<TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="48dp" >
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/imgLogoCosoft"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/logo_cosoft" />
        <ImageView
            android:id="@+id/imgLogoFeelife"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/logo_feelife" />
    </TableRow>
</TableLayout>

这是我使用 Linearlayout 时的活动 XML:

<LinearLayout
    android:id="@+id/linearSplash"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_gravity="bottom"
    android:paddingTop="20dp"
    android:layout_alignParentBottom="true">
        <ImageView
            android:id="@+id/imgLogoCosoft"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/logo_cosoft" />
        <ImageView
            android:id="@+id/imgLogoFeelife"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/logo_feelife" />
</LinearLayout>

这是我使用 Linearlayout 时的 Java 代码:

int DisplayWidth = Funzioni.ScreenWidth (SplashScreen.this);
int DisplayHeight = Funzioni.ScreenHeight(SplashScreen.this);

imgLogoCosoft = (ImageView)findViewById(R.id.imgLogoCosoft);
LayoutParams params_imgLogoCosoft = new LayoutParams(DisplayWidth,(DisplayHeight/100)*10);
imgLogoCosoft.setLayoutParams(params_imgLogoCosoft);

imgLogoFeelife = (ImageView)findViewById(R.id.imgLogoFeelife);
LayoutParams params_imgLogoFeelife = new LayoutParams(DisplayWidth,(DisplayHeight/100)*10);
imgLogoFeelife.setLayoutParams(params_imgLogoFeelife);

建议?

提前致谢!

4

1 回答 1

0

好的,我会回答自己的。

将图像放置在活动的底部并调整其大小,而不是

LayoutParams params_imgLogoCosoft = new LayoutParams(DisplayWidth,(DisplayHeight/100)*10);
imgLogoCosoft.setLayoutParams(params_imgLogoCosoft);

我用过

imgLogoCosoft.getLayoutParams().width = DisplayWidth/10;

这是活动的 XML:

<ImageView
    android:id="@+id/imgSfondoSplash"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/back_splash" />

<ProgressBar
    android:id="@+id/pgbSplash"
    style="?android:attr/progressBarStyleLarge"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

<RelativeLayout
    android:id="@+id/linearLayout1"
    android:layout_below="@+id/imgSfondoSplash"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"">
        <ImageView
            android:id="@+id/imgLogoCosoft"
            android:layout_alignParentBottom="true"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/logo_cosoft" />
        <ImageView
            android:id="@+id/imgLogoFeelife"
            android:layout_alignParentBottom="true"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/logo_feelife" />
</RelativeLayout>

这是活动的代码:

imgSfondoSplash = (ImageView)findViewById(R.id.imgSfondoSplash);
RelativeLayout.LayoutParams params_imgSfondoSplash = new RelativeLayout.LayoutParams(DisplayWidth,(DisplayHeight/100)*90);
imgSfondoSplash.setLayoutParams(params_imgSfondoSplash);

    imgLogoCosoft = (ImageView)findViewById(R.id.imgLogoCosoft);
    RelativeLayout.LayoutParams lp_imgLogoCosoft=new RelativeLayout.LayoutParams((DisplayWidth / 10), (DisplayWidth / 10));
    lp_imgLogoCosoft.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    imgLogoCosoft.setLayoutParams(lp_imgLogoCosoft);

    imgLogoFeelife = (ImageView)findViewById(R.id.imgLogoFeelife);
    RelativeLayout.LayoutParams lp_imgLogoFeelife=new RelativeLayout.LayoutParams((DisplayWidth / 10), (DisplayWidth / 10));
    lp_imgLogoFeelife.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    lp_imgLogoFeelife.addRule(RelativeLayout.RIGHT_OF, R.id.imgLogoCosoft);
    imgLogoFeelife.setLayoutParams(lp_imgLogoFeelife);

我希望这对其他开发人员有用。

于 2013-09-20T14:25:39.863 回答