Android版的ImageButton不显示在屏幕的右侧 [英] Android ImageButton not displaying on right side of the screen

查看:165
本文介绍了Android版的ImageButton不显示在屏幕的右侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能得到的ImageButton显示了在屏幕的右侧。如果我把内心的LinearLayout上面的ImageButton,它会显示在左侧,但是当我把它内部的LinearLayout下方,它不会显示在所有。下面是XML文件。

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT
    机器人:方向=横向机器人:填充=2DIP
    风格=@风格/ default_style>    <的LinearLayout
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID /布局1
        机器人:方向=垂直>        < TableLayout的android:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / headerTable
            机器人:stretchColumns =0.1>
            <的TableRow的android:layout_width =FILL_PARENT机器人:ID =@ + ID / headerRow
                机器人:layout_height =match_parent>
                <的TextView的android:文本=全名机器人:ID =@ + ID /全名
                    机器人:layout_height =WRAP_CONTENT机器人:layout_gravity =左
                    机器人:layout_width =FILL_PARENT机器人:文字样式=大胆
                    风格=@风格/ default_style>< / TextView的>
                <的TextView的android:文本=ContentTimestamp机器人:ID =@ + ID / content_timestamp
                    机器人:layout_height =WRAP_CONTENT机器人:layout_gravity =右
                    机器人:layout_width =FILL_PARENT
                    风格=@风格/ default_style>< / TextView的>
                < ImageView的机器人:ID =@ + ID / hasGeoLocation
                    机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
                    机器人:SRC =@绘制/图机器人:paddingLeft =2DIP机器人:知名度=看得见>
                < / ImageView的>
            < /&的TableRow GT;        < / TableLayout>        < TextView的机器人:ID =@ + ID /内容
            机器人:文字=内容等等等等等等等等等等等等等等等等等等
            机器人:layout_width =FILL_PARENT机器人:比重=center_vertical
            机器人:TEXTSIZE =16dip机器人:layout_height =WRAP_CONTENT
            机器人:paddingLeft =5dip
            风格=@风格/ default_style> < / TextView的>    < / LinearLayout中>    < RelativeLayout的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT>
        < ImageButton的机器人:ID =@ + ID / hasAudio
            机器人:layout_width =50像素
            机器人:layout_height =50像素
            机器人:layout_toRightOf =@ + ID /布局1
            机器人:重力=右
            机器人:SRC =@绘制/播放
            机器人:知名度=看得见/>
    < / RelativeLayout的>
< / LinearLayout中>


解决方案

下面是另一个可能的解决方案。可以在的LinearLayout的重量设置为一个值,如1。这将允许的ImageButton到母体而非外的限制内呈现

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT
    机器人:方向=横向机器人:填充=2DIP
    风格=@风格/ default_style>
    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=垂直
        机器人:重力=center_vertical
        机器人:layout_weight =1>
        < TableLayout的android:layout_width =FILL_PARENT
    ...

有关参考文档:
http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#weight

I can't get the ImageButton to show up on the right side of the screen. If I place the ImageButton above the inner LinearLayout, it will show up on the left side, but when I place it below the inner LinearLayout, it doesn't display at all. Below is the xml file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="horizontal" android:padding="2dip"
    style="@style/default_style">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/layout1"
        android:orientation="vertical" >    

        <TableLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/headerTable"
            android:stretchColumns="0,1">
            <TableRow android:layout_width="fill_parent" android:id="@+id/headerRow"
                android:layout_height="match_parent">
                <TextView android:text="Fullname" android:id="@+id/fullname"
                    android:layout_height="wrap_content" android:layout_gravity="left"
                    android:layout_width="fill_parent" android:textStyle="bold"
                    style="@style/default_style"></TextView>
                <TextView android:text="ContentTimestamp" android:id="@+id/content_timestamp"
                    android:layout_height="wrap_content" android:layout_gravity="right"
                    android:layout_width="fill_parent"
                    style="@style/default_style"></TextView>
                <ImageView android:id="@+id/hasGeoLocation"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:src="@drawable/map" android:paddingLeft="2dip" android:visibility="visible">
                </ImageView>    
            </TableRow>

        </TableLayout>

        <TextView android:id="@+id/content"
            android:text="Content blah blah blah blah blah blah blah blah blah"
            android:layout_width="fill_parent" android:gravity="center_vertical"
            android:textSize="16dip" android:layout_height="wrap_content"
            android:paddingLeft="5dip"
            style="@style/default_style"> </TextView>

    </LinearLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >                      
        <ImageButton android:id="@+id/hasAudio"
            android:layout_width="50px"
            android:layout_height="50px"
            android:layout_toRightOf="@+id/layout1"
            android:gravity="right"
            android:src="@drawable/play"
            android:visibility="visible" />     
    </RelativeLayout>
</LinearLayout>

解决方案

Here's another possible solution. You can set the weight of the inner LinearLayout to a value, such as 1. That will allow the ImageButton to render within the constraints of the parent rather than outside.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="horizontal" android:padding="2dip"
    style="@style/default_style">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center_vertical" 
        android:layout_weight="1">
        <TableLayout android:layout_width="fill_parent"
    ...

For reference to the docs: http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#weight

这篇关于Android版的ImageButton不显示在屏幕的右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆