4

背景画像が固定されており、その上に別の画像が表示されています。これがxmlです-

<AbsoluteLayout 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:orientation="vertical" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  >
 <ImageView 
     android:id="@+id/test_image"
     android:src="@drawable/lpch_1"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
        />
<ImageView 
     android:id="@+id/search_pin"
     android:src="@drawable/pin"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_y="100px" 
     android:layout_x="100px"
        />  
 </AbsoluteLayout>

では、image-id search_pinのlayout_x、layout_yをコードから変更するにはどうすればよいですか?

4

3 に答える 3

6

Try this:

AbsoluteLayout.LayoutParams params = ((AbsoluteLayout.LayoutParams) test_image.getLayoutParams());
params.x = 100;
params.y = 100;
test_image.setLayoutParams(params); 
于 2011-10-14T10:43:44.763 に答える
3

絶対レイアウトは非推奨です。

この場合、FrameLayoutを使用することをお勧めします。

もう1つ、dpまたはdipは、 px以外の方が好ましいです。

Androidは複数の画面解像度をサポートしているため、特定のウィジェットの固定座標について言及するのはよくありません。

于 2011-10-14T10:37:29.400 に答える
0

Absolutelayoutの代わりに使用する必要がありますrelativelayout:

android:layout_x="100dp" ピクセルではない

android:layout_y="100dp"

両方に使用されabsolutelayoutます。

于 2015-09-30T08:37:33.323 に答える