android xml布局问题

发布于 2024-10-14 08:59:36 字数 5111 浏览 7 评论 0原文

我已经花了几个小时在这上面,这是一个布局问题。有人可以告诉我如何在同一活动中显示图像和视图切换器。

<RelativeLayout 
            xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:myapp="http://schemas.android.com/apk/res/rg.client.muscle"
            android:layout_width="fill_parent"
        android:layout_height="fil_parent">
    <ViewSwitcher 
        android:id="@+id/relative"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true">

        <!-- contains two relative layouts of same sizes 
        containing same elements just with switched positions -->

        <RelativeLayout 

            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentBottom="true" >

            <com.admob.android.ads.AdView 
                android:id="@+id/adv" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                myapp:backgroundColor="#000000" 
                myapp:primaryTextColor="#FFFFFF" 
                myapp:secondaryTextColor="#CCCCCC"
                myapp:refreshInterval="30" >
            </com.admob.android.ads.AdView>

            <LinearLayout 
                android:id="@+id/linear" 
                android:orientation="horizontal" 
                android:weightSum="100" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:layout_above="@id/adv" >

                <Button 
                    android:id="@+id/but_prev2" 
                    android:text="Previous" 
                    android:layout_width="0dp" 
                    android:layout_height="wrap_content" 
                    android:layout_weight="30" >
                </Button>

                <Button 
                    android:id="@+id/but_more2" 
                    android:text="More" 
                    android:layout_width="0dp" 
                    android:layout_height="wrap_content" 
                    android:layout_weight="40" >
                </Button>

                <Button 
                    android:id="@+id/but_next2" 
                    android:text="Next" 
                    android:layout_width="0dp" 
                    android:layout_height="wrap_content" 
                    android:layout_weight="30">
                </Button>
            </LinearLayout>
        </RelativeLayout>

        <RelativeLayout 

            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentBottom="true" >

            <LinearLayout 
                android:id="@+id/linear2" 
                android:orientation="horizontal"  
                android:weightSum="100" 
                android:layout_width="fill_parent"    
                android:layout_height="wrap_content" 
                android:layout_alignParentBottom="true" >

                <Button 
                    android:id="@+id/but_prev" 
                    android:text="Previous" 
                    android:layout_width="0dp" 
                    android:layout_height="wrap_content" 
                    android:layout_weight="30">
                </Button>

                <Button 
                    android:id="@+id/but_more" 
                    android:text="More" 
                    android:layout_width="0dp" 
                    android:layout_height="wrap_content" 
                    android:layout_weight="40">
                </Button>

                <Button 
                    android:id="@+id/but_next" 
                    android:text="Next" 
                    android:layout_width="0dp"   
                    android:layout_height="wrap_content" 
                    android:layout_weight="30">
                </Button>

            </LinearLayout>

            <com.admob.android.ads.AdView 
                android:id="@+id/adv2" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:layout_above="@id/linear2" 
                myapp:backgroundColor="#000000" 
                myapp:primaryTextColor="#FFFFFF" 
                myapp:secondaryTextColor="#CCCCCC"
                myapp:refreshInterval="30">
            </com.admob.android.ads.AdView>
        </RelativeLayout>
    </ViewSwitcher>

    <ImageView 
        android:id="@+id/image"
        android:layout_above="@id/relative"
        android:padding="2pt" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" >
    </ImageView>
</RelativeLayout>

如果我把图像视图放在第一位,那么每次加载新图像时,按钮就会消失,整个布局似乎会重新膨胀

更新:

布局必须在顶部有一个图像视图,然后有一个视图切换器。

I already spent hours on this, its a layout issue. can someone tell me how to show both image and view switcher in the same activity.

<RelativeLayout 
            xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:myapp="http://schemas.android.com/apk/res/rg.client.muscle"
            android:layout_width="fill_parent"
        android:layout_height="fil_parent">
    <ViewSwitcher 
        android:id="@+id/relative"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true">

        <!-- contains two relative layouts of same sizes 
        containing same elements just with switched positions -->

        <RelativeLayout 

            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentBottom="true" >

            <com.admob.android.ads.AdView 
                android:id="@+id/adv" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                myapp:backgroundColor="#000000" 
                myapp:primaryTextColor="#FFFFFF" 
                myapp:secondaryTextColor="#CCCCCC"
                myapp:refreshInterval="30" >
            </com.admob.android.ads.AdView>

            <LinearLayout 
                android:id="@+id/linear" 
                android:orientation="horizontal" 
                android:weightSum="100" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:layout_above="@id/adv" >

                <Button 
                    android:id="@+id/but_prev2" 
                    android:text="Previous" 
                    android:layout_width="0dp" 
                    android:layout_height="wrap_content" 
                    android:layout_weight="30" >
                </Button>

                <Button 
                    android:id="@+id/but_more2" 
                    android:text="More" 
                    android:layout_width="0dp" 
                    android:layout_height="wrap_content" 
                    android:layout_weight="40" >
                </Button>

                <Button 
                    android:id="@+id/but_next2" 
                    android:text="Next" 
                    android:layout_width="0dp" 
                    android:layout_height="wrap_content" 
                    android:layout_weight="30">
                </Button>
            </LinearLayout>
        </RelativeLayout>

        <RelativeLayout 

            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentBottom="true" >

            <LinearLayout 
                android:id="@+id/linear2" 
                android:orientation="horizontal"  
                android:weightSum="100" 
                android:layout_width="fill_parent"    
                android:layout_height="wrap_content" 
                android:layout_alignParentBottom="true" >

                <Button 
                    android:id="@+id/but_prev" 
                    android:text="Previous" 
                    android:layout_width="0dp" 
                    android:layout_height="wrap_content" 
                    android:layout_weight="30">
                </Button>

                <Button 
                    android:id="@+id/but_more" 
                    android:text="More" 
                    android:layout_width="0dp" 
                    android:layout_height="wrap_content" 
                    android:layout_weight="40">
                </Button>

                <Button 
                    android:id="@+id/but_next" 
                    android:text="Next" 
                    android:layout_width="0dp"   
                    android:layout_height="wrap_content" 
                    android:layout_weight="30">
                </Button>

            </LinearLayout>

            <com.admob.android.ads.AdView 
                android:id="@+id/adv2" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:layout_above="@id/linear2" 
                myapp:backgroundColor="#000000" 
                myapp:primaryTextColor="#FFFFFF" 
                myapp:secondaryTextColor="#CCCCCC"
                myapp:refreshInterval="30">
            </com.admob.android.ads.AdView>
        </RelativeLayout>
    </ViewSwitcher>

    <ImageView 
        android:id="@+id/image"
        android:layout_above="@id/relative"
        android:padding="2pt" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" >
    </ImageView>
</RelativeLayout>

If I put the imageview first then each time a new image is loaded the buttons disappear and the whole layout seems to be re inflated

Update:

The layout must have an image view at the top then a view switcher.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别在捏我脸啦 2024-10-21 08:59:36

我想这很大程度上与您无法读取 XML 有关。如果它看起来像您最初粘贴到此处的方式,那就是。您的第一个问题是您的根RelativeLayout 标记中没有指定大小的内容。在大多数情况下,您的根布局应设置为 fill_parentlayout_width,与 layout_height 相同。您还需要您的模式规范(即 xmlns:android="http://schemas.android.com/apk/res/android" 虽然我假设您只是忽略了它,因为您'实际上,

您可能还需要记住,因为大多数内容都设置为 wrap_content 高度,如果它超过了屏幕的高度,其中一些将不可见。 ,因此您可以考虑将内部部分包装到 ScrollView 中。

编辑:我再次建议将您的relativelayout(根元素)的高度设置为 fill_parent。首先定义您的 ImageView,保留 alignParentTop="true",然后定义您的 ViewSwitcher,并为其指定 layout_below="@id/image" 属性。

I imagine a lot of it has to do with you not being able to read your XML. If it looks anything like the way you originally pasted it in here, that is. Your first problem is that you have nothing in your root RelativeLayout tag specifying a size. Your root layout should be in most cases set to a layout_width of fill_parent, same with the layout_height. You also need your schema specification (i.e. xmlns:android="http://schemas.android.com/apk/res/android" although I'm assuming you just left that out, since you're actually getting it to compile.

You also may want to keep in mind, since most everything is set to wrap_content for height, if it ever exceeds the height of the screen, some of it will not be visible, so you may consider wrapping the inner portion into a ScrollView.

EDIT: Again, I'd suggest setting your RelativeLayout (root element) to have a height of fill_parent. Try defining your ImageView first, leaving it with alignParentTop="true", then define your ViewSwitcher, and give it the layout_below="@id/image" attribute.

请叫√我孤独 2024-10-21 08:59:36

还有个小建议,使用include布局,会更清晰。

 <include layout="@layout/my_other_layout" />

And small advice, use include layout, it will be more clear.

 <include layout="@layout/my_other_layout" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文