开发者

Android: Fit in three large imageviews

I have an imageview that displays an image that covers about half the screen. This is the class:

public class DialButton2 extends ImageView{

    public DialButton2(Context context) {
        super(context);
        this.setImageResource(R.drawable.dialpad);
    }

    public DialButton2(Context context, AttributeSet attrs){
        super(context, attrs);
        this.setImageResour开发者_Go百科ce(R.drawable.dialpad);
    }

}

My problem is how to fit THREE of these in on the screen. If I add one of these in using xml, I can use wrap_content and it will wrap content, I can use fill_parent and it will scale up and fill parent, but if I need to fit in three in a row, how should I force xml to scale them and fit them all in as a group of three? My current code doesnt work, it puts two in a row in and leaves out the third (because it occupies space outside of the screen):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.com.com.DialButton2
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitCenter"
    />
<com.com.com.DialButton2
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitCenter"
    />
<com.com.com.DialButton2
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitCenter"
    />
</LinearLayout>


<com.com.com.DialButton2
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:layout_weight="1"
/>

Use this for all 3 views


You can use layout weights (equal ones for all 3 subviews) while setting their layout widths to 0px. This will make them each take up proportional measures to combine to fill the available space.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜