【问题标题】:Layout is resizing after clicking on Button单击按钮后布局正在调整大小
【发布时间】:2013-02-11 19:16:39
【问题描述】:

我创建了一个线性布局,在其中添加了水平滚动视图,并在运行时在水平滚动视图上添加了几个按钮。最初它看起来不错,但是当我单击“类别”按钮时,单击几个按钮后,类别容器会调整大小,如图所示。

请帮助我为什么会发生什么问题 谢谢。

【问题讨论】:

  • 在此处粘贴一些代码,以帮助我们以更好的模式解决您的问题
  • 高度是否也在缩小?只是换词有问题吗?
  • 你能发布布局的 XML 吗?
  • @fahad 身高正在缩小
  • 在图形视图中打开 xml。将红色选中表格中的优惠券和类别一一设置。看看他们中的哪些人倾向于降低身高。重叠的文本视图或 textView 的固定高度是这里的罪魁祸首

标签: android android-layout android-button android-scrollview


【解决方案1】:
Here is Button.xml file which i am inflating at runtime .

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Button_category_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:paddingBottom="10dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="10dp"
android:textSize="16dp"
android:textStyle="bold" />

【讨论】:

    【解决方案2】:

    这是布局文件

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_view_deals_screen"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white" >
    
    <RelativeLayout
        android:id="@+id/RelativeLayout_category_panel_main"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/color_category_panel_bg"
        android:visibility="gone" >
    
        <ImageView
            android:id="@+id/ImageView_previous"
            android:layout_width="15dp"
            android:layout_height="20dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:src="@drawable/arrow_left"
            android:visibility="gone" />
    
        <HorizontalScrollView
            android:id="@+id/ScrollView_category_panel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/ImageView_next"
            android:layout_toRightOf="@+id/ImageView_previous"
            android:fadingEdgeLength="15dp"
            android:scrollbars="none" >
    
            <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/Layout_category_panel_container"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
            </LinearLayout>
        </HorizontalScrollView>
    
        <ImageView
            android:id="@+id/ImageView_next"
            android:layout_width="15dp"
            android:layout_height="20dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/arrow_right"
            android:visibility="gone" />
    </RelativeLayout>
    
    <com.techdeals.rest.ui.widget.IndexableListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/RelativeLayout_category_panel_main"
        android:divider="@drawable/list_divider"
        android:drawSelectorOnTop="false" />
    
    <ImageView
        android:id="@+id/ImageView_list_divider"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@android:id/list"
        android:scaleType="fitXY"
        android:src="@drawable/list_divider" />
    

    【讨论】:

    • relativeLayout 中的所有内容-> 将其高度设置为 25dp。那你就出发吧。
    • @FahadIshaque 感谢您的回答,但按钮上的文字来自底部
    • 也修复它的高度。您的高度参数 -> 包装内容相矛盾,这就是发生此问题的原因
    猜你喜欢
    • 2012-03-23
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 2015-08-16
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    相关资源
    最近更新 更多