0

写真を表示するシンプルなアプリを作ろうとしています。画像は画面に合わせて拡大縮小され、画像の下に次へボタンと前へボタンがあります。次のボタンと前のボタンをボタンに配置したいのですが、画像のボタンに描画され続けます。したがって、新しい画像を表示するたびに、画像の大きさに応じて上下に移動します。

ここで次の解決策を見つけましたが、うまくいきません。

android:gravity="bottom"  
android:layout_alignParentBottom="true"

これはxmlファイルです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/backFeetGallery"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/viewimage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/background" />

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:gravity="bottom"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/butLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="12px"
            android:text=" Left "
            android:textColor="#ff0000ff" />

        <Button
            android:id="@+id/butFavrest"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="12px"
            android:text=" Favrets "
            android:textColor="#ff0000ff" />

        <Button
            android:id="@+id/butEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="12px"
            android:text=" email "
            android:textColor="#ff0000ff" />

        <Button
            android:id="@+id/butRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="12px"
            android:text=" Right "
            android:textColor="#ff0000ff" />
    </LinearLayout>

</LinearLayout>

ソースコード

public class cFeetView extends cBaseView implements OnClickListener {
    cFileNames mFileNames;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.feet);

        // add listeners
        View mLeft = findViewById(R.id.butRight);
        mLeft.setOnClickListener(this);

        // add listeners
        View mRight = findViewById(R.id.butLeft);
        mRight.setOnClickListener(this);

        mFileNames=new cFileNames();
        mFileNames.Start();
        DrawFeet();
    }

    public void DrawFeet()
    {
        int screenHeight;
        ImageView picImage = (ImageView) findViewById(R.id.viewimage);// R.id.viewpic);
        try {
            String FileName = "canon20.png";
            FileName=mFileNames.Current();
            AssetManager assetManager = getAssets();
            InputStream inputStream;
            inputStream = assetManager.open(FileName);
            Bitmap icon = BitmapFactory.decodeStream(inputStream);

            int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
            screenHeight = getWindowManager().getDefaultDisplay().getHeight();

            int bw = icon.getWidth();
            int bh=icon.getHeight();
            float t = (float) screenWidth / (float) bw;

            int iConHeight=(int)((float)bh*t);
            picImage.setImageBitmap(icon);

            // scale it
            picImage.getLayoutParams().width = screenWidth;
            picImage.getLayoutParams().height =iConHeight;
            Bitmap scaledIcon = Bitmap.createScaledBitmap(icon, screenWidth, iConHeight, false);

        } catch (IOException e) {
        }
    }
    // set the top and buttom margins

    public void onClick(View v)
    {
        Intent i;
        switch(v.getId())
        {
        case R.id.butLeft:
            mFileNames.Pre();   
            DrawFeet();
            break;
        case R.id.butRight:
            mFileNames.Next();
            DrawFeet();
            break;              
        }
    }
} // end class
4

3 に答える 3

2

LinearLayout の代わりに、xml ファイルで RelativeLayout を使用します。

LinearLayout は、それらを水平方向または垂直方向に配置するためにのみ使用されます。

于 2012-08-29T07:20:49.830 に答える
0

alignParentBottom を使用するには、RelativeLayout を使用する必要があります。そして、重力属性は必要ありません。

あなたの特定のシナリオに対する私の提案は、あなたが RelativeLayout を持っていて、すべてのボタンを一番下に配置された LinearLayout とその上に ImageView を配置することです。

擬似:

<RelativeLayout>
   <ImageView />

   <LinearLayout
      android:layout_below="@ImageView_id"
      android:layout_alignParentBottom=true>
   </LinearLayout>
</RelativeLayout>

あなたのxmlで編集:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/backFeetGallery"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/viewimage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/background" />

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_below="@id/viewimage"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/butLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="12px"
            android:text=" Left "
            android:textColor="#ff0000ff" />

        <Button
            android:id="@+id/butFavrest"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="12px"
            android:text=" Favrets "
            android:textColor="#ff0000ff" />

        <Button
            android:id="@+id/butEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="12px"
            android:text=" email "
            android:textColor="#ff0000ff" />

        <Button
            android:id="@+id/butRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="12px"
            android:text=" Right "
            android:textColor="#ff0000ff" />
    </LinearLayout>

</RelativeLayout>
于 2012-08-28T23:32:08.503 に答える
0

RelativeLayout にすべてを含める必要があります。たとえば、画面の下部中央に配置された 1 つのボタン用に作成したこのサンプル コードを見てください。

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="Button" />

そして、ここにあなたのレイアウトの完全なレイアウトファイルがあります

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="Button" />

<Button
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="Button" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="Button" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/button2"
    android:text="Button" />

<Button
    android:id="@+id/button5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/button3"
    android:text="Button" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="38dp"
    android:src="@android:drawable/gallery_thumb" />

こう見えて、 ここに画像の説明を入力

于 2012-08-28T23:38:16.643 に答える