【问题标题】:image stretched in tabs android在标签android中拉伸的图像
【发布时间】:2012-08-05 06:49:12
【问题描述】:

我的应用中有一个 TabHost,我试图将图像放入文本中。 我的问题是图像拉伸到整个屏幕而不是实际尺寸。我在高度和宽度中使用“wrap_content”,它仍然在做。当我将相同的图像放入其他带有“wrap_content”的商品时,就可以了。只有在标签中它很奇怪。看起来就是这样:

而不是像这样:

这是我的代码:

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

           <TabWidget
               android:id="@android:id/tabs"
               android:layout_width="wrap_content"
               android:layout_height="60dp"
               android:gravity="center_vertical"
               android:showDividers="none" >

            </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:id="@+id/tab1"
                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:text="start" />

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

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

            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                 <Button
                    android:id="@+id/button3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="second tab B" />

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

            </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>

谢谢!

【问题讨论】:

    标签: android image tabs


    【解决方案1】:

    很晚才回答,我敢肯定你不在乎,但其他人可能会。

    这是另一个Link

    九色块生成器可让您根据指定的源图稿快速生成不同屏幕密度的简单九色块。

    如果您对此有任何问题,请查看Here。阅读CommonsWare答案。

    【讨论】:

      【解决方案2】:

      您需要使用 9-patch 图像。

      这里有一个指南,可以帮助您创建 9-patch 图像。 http://radleymarx.com/blog/simple-guide-to-9-patch/

      【讨论】:

        【解决方案3】:

        我使用相对布局修复它,如下所示:

        <TabHost
            android:id="@+id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.8" >
        
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >
        
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="0.1" >
        
                    <TabWidget
                        android:id="@android:id/tabs"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="false"
                        android:layout_centerHorizontal="true"
                        android:gravity="center_vertical"
                        android:showDividers="none" >
                    </TabWidget>
        
                </RelativeLayout>
        
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="0.9" >
        
                    <LinearLayout
                        android:id="@+id/tab1"
                        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:text="start" />
        
                        <Button
                            android:id="@+id/button2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="stop" />
        
                        <TextView
                            android:id="@+id/textView1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="first tab" />
        
                    </LinearLayout>
        
                    <LinearLayout
                        android:id="@+id/tab2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >
        
                         <Button
                            android:id="@+id/button3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="second tab B" />
        
                        <TextView
                            android:id="@+id/textView1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Secont tab" />
        
                    </LinearLayout>
                </FrameLayout>
            </LinearLayout>
        </TabHost>
        

        还是谢谢!!

        【讨论】:

          【解决方案4】:

          您可以尝试像这样从 java 代码中缩放图像视图;

          yourImageView.setScaleType(ScaleType.CENTER);
          

          或者像这样来自 XML;

          android:scaleType="fitCenter"
          

          【讨论】:

            猜你喜欢
            • 2015-07-11
            • 1970-01-01
            • 2015-06-17
            • 1970-01-01
            • 2019-05-10
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-03-16
            相关资源
            最近更新 更多