布局:文本视图应自动缩放

时间:2014-04-03 08:54:12

标签: android xml layout textview

我创建了一个布局,它在顶部,中间文本和最后一个按钮上有一个imageview。现在我希望所有这些元素都在一个页面上,这意味着textview应该自动缩放其大小。实际上在我的布局中我只能看到imageview和textview,看到我必须滚动的按钮。

我应该自己更改textview的大小,为不同的屏幕尺寸添加不同的布局还是有另一种可能性?

我的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <HorizontalScrollView
            android:id="@+id/horizontalScrollView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:orientation="horizontal" >

                <RelativeLayout
                    android:id="@+id/l1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal" >

                    <ImageView
                        android:id="@+id/imageView2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:scaleType="centerInside"
                        android:src="@drawable/crunch1" />

                    <ImageView
                        android:id="@+id/button2links"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/imageView2"
                        android:layout_centerHorizontal="true"
                        android:scaleType="centerInside"
                        android:src="@drawable/links2" />
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/b2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_toRightOf="@+id/l1"
                    android:orientation="horizontal" >

                    <ImageView
                        android:id="@+id/imageView1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/crunch2" />

                    <ImageView
                        android:id="@+id/button2rechts"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/imageView1"
                        android:layout_centerHorizontal="true"
                        android:adjustViewBounds="true"
                        android:src="@drawable/rechts2" />
                </RelativeLayout>
            </RelativeLayout>
        </HorizontalScrollView>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Crunch"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/crunch" />

        <ImageButton
            android:id="@+id/pause"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:onClick="verlaufKlick"
            android:src="@drawable/ic_launcher"
            android:visibility="invisible"
            android:background="?android:selectableItemBackground" 
            />
    </LinearLayout>
</ScrollView>

That`s what I want!

1 个答案:

答案 0 :(得分:0)

现在我用它:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    android:orientation="vertical" >

            <HorizontalScrollView
                android:id="@+id/horizontalScrollView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:orientation="horizontal" >



                    <RelativeLayout
                        android:id="@+id/l1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="horizontal" >

                        <ImageView
                            android:id="@+id/imageView2"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:scaleType="centerInside"
                            android:src="@drawable/crunch1" />

                        <ImageView
                            android:id="@+id/button2links"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/imageView2"
                            android:layout_centerHorizontal="true"
                            android:scaleType="centerInside"
                            android:src="@drawable/links2" />


                        <ImageView
                            android:id="@+id/imageView1"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:src="@drawable/crunch2" />

                        <ImageView
                            android:id="@+id/button2rechts"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/imageView1"
                            android:layout_centerHorizontal="true"                            
                            android:src="@drawable/rechts2" />
                    </RelativeLayout>

            </HorizontalScrollView>

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:text="Crunch"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:layout_below="@+id/horizontalScrollView1" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:text="@string/crunch" 
                android:layout_below="@+id/textView2"
                android:layout_above="@+id/pause"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"/>

            <ImageButton
                android:id="@+id/pause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"                
                android:onClick="verlaufKlick"
                android:src="@drawable/ic_launcher"
                android:visibility="invisible"
                android:background="?android:selectableItemBackground"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"

                />


</RelativeLayout>
相关问题