我必须在活动两个图像视图的中心|底部水平对齐,我必须以屏幕宽度百分比(例如屏幕宽度的10%)调整图像视图的大小。
如果我不应用调整大小,我在中心有两个图像视图,但是太大了; 如果我申请调整大小,我只有第一个在中心;另一个消失了!
我尝试使用Linearlayouts(orientation = horizontal)和Tablelayout ......没有结果!
当我使用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);
建议?
提前致谢!
答案 0 :(得分: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);
我希望这对其他开发者有用。