标签: android-linearlayout

android视图中出现的常见问题,解析XML时出错:未绑定的前缀

我在android视图中经常遇到问题Error parsing XML: unbound prefix on Line 2.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:id="@+id/myScrollLayout" 
android:layout_width="fill_parent"  android:layout_height="wrap_content">
    <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" 
    android:text="Family" android:id="@+id/Family" 
    android:textSize="16px" android:padding="5px" 
    android:textStyle="bold" android:gravity="center_horizontal">
    </TextView>

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="vertical" android:scrollbars="vertical">
        <LinearLayout android:orientation="vertical" android:id="@+id/myMainLayout" 
        android:layout_width="fill_parent"  android:layout_height="wrap_content">
        </LinearLayout>
    </ScrollView>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

xml eclipse android android-linearlayout

290
推荐指数
8
解决办法
21万
查看次数

Android中的线性布局和重量

我总是在Android文档中读到这个有趣的重量值.现在我想第一次尝试它,但它根本不工作.

据我所知,这个布局的文件:

  <LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal">

     <Button
        android:text="Register"
        android:id="@+id/register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dip"
        weight="1" />

     <Button
        android:text="Not this time"
        android:id="@+id/cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dip"
        weight="1" />

  </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

应创建两个水平对齐的按钮,并平等分享空间.问题是两个按钮不会增长以填充空间.

我想按钮增长并填满整行.如果两个按钮都设置为仅匹配父按钮,则显示第一个按钮并填充整行.

android android-linearlayout android-layout-weight

251
推荐指数
9
解决办法
37万
查看次数

Android LinearLayout渐变背景

我无法将渐变背景应用于LinearLayout.

这应该比我读过的内容相对简单,但它似乎没有用.作为参考,我正在开发2.1-update1.

header_bg.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="90"
        android:startColor="#FFFF0000"
        android:endColor="#FF00FF00"
        android:type="linear"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

main_header.xml:

<?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="50dip"
    android:orientation="horizontal"
    android:background="@drawable/header_bg">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

如果我将@ drawable/header_bg更改为颜色 - 例如#FF0000,它可以正常工作.我错过了一些明显的东西吗?

android gradient android-layout android-linearlayout

235
推荐指数
6
解决办法
24万
查看次数

如何使LinearLayout可滚动?

我在屏幕上有很多项目,我需要使用滚动条,以便用户可以向下滚动.但是,滚动要么不可见,要么不起作用.如何将滚动条添加到LinearLayout

android android-linearlayout

232
推荐指数
3
解决办法
28万
查看次数

是否可以在android linearlayout的宽度上均匀分布按钮

我有一个线性布局(水平定向),包含3个按钮.我希望3个按钮具有固定的宽度,并且均匀分布在线性布局的宽度上.

我可以通过将linearlayout的重力设置为居中然后调整按钮的填充来管理这个,但这适用于固定宽度,不适用于更改设备或方向.

<LinearLayout android:id="@+id/LinearLayout01" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:gravity="center">

<Button 
android:id="@+id/btnOne"
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:width="120dip"></Button>

<Button 
android:id="@+id/btnTwo"
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:width="120dip"></Button>


<Button 
android:id="@+id/btnThree"
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:width="120dip"></Button>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android android-linearlayout

229
推荐指数
9
解决办法
20万
查看次数

如何使用复合drawable而不是包含ImageView和TextView的LinearLayout

根据我的代码运行新的Lint工具.它提出了很多好的建议,但这个我无法理解.

此标签及其子代可以替换为一个和复合drawable

问题:检查当前节点是否可以使用复合drawables替换为TextView.

包含ImageView和TextView的LinearLayout可以作为复合drawable更有效地处理

这是我的布局

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerInParent="true">

<ImageView 
    android:id="@+id/upImage"
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:layout_gravity="center_vertical"
    android:scaleType="centerInside"
    android:src="@drawable/up_count_big">
</ImageView>

<TextView
    android:id="@+id/LikeCount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="2dp"
    android:layout_marginBottom="1dp"
    android:textColor="@color/gray"
    android:textSize="16sp"
    android:layout_gravity="center_vertical">
</TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,有人能提供一个如何制作复合可绘制的具体例子吗?

android textview android-layout android-linearlayout compound-drawables

189
推荐指数
2
解决办法
10万
查看次数

LinearLayout,RelativeLayout和AbsoluteLayout有什么区别?

我对LinearLayout,RelativeLayout和AbsoluteLayout之间的区别感到困惑.有人可以告诉我他们之间的确切差异吗?

android android-layout android-linearlayout android-relativelayout android-framelayout

173
推荐指数
3
解决办法
21万
查看次数

如何将内容集中在线性布局中?

我试图将ImageView内部LinearLayout水平和垂直居中,但我无法做到.我不使用a的主要原因RelativeLayout是因为我需要layout_weight(我Activity的四列应该被平分,并且还响应不同的屏幕宽度,每列都有一个ImageView居中和未拉伸).

到目前为止,这是我的xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000"
    android:baselineAligned="false"
    android:gravity="center"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Main" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1" >

        <ImageView
            android:id="@+id/imageButton_speak"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/image_bg"
            android:src="@drawable/ic_speak" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1" >

        <ImageView
            android:id="@+id/imageButton_readtext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/image_bg"
            android:src="@drawable/ic_readtext" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1" >

        <ImageView
            android:id="@+id/imageButton_edit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/image_bg"
            android:src="@drawable/ic_edit" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1" >

        <ImageView
            android:id="@+id/imageButton_config"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-linearlayout

142
推荐指数
4
解决办法
17万
查看次数

Android LinearLayout:在LinearLayout周围添加阴影边框

我想创建此LinearLayout的相同边框作为示例:

在此输入图像描述

在这个例子中,我们可以看到linearLayout周围的边界不一样.如何使用XML可绘制文件创建它?

现在,我只能在LinearLayout周围创建一个简单的边框,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  <corners
      android:radius="1dp"
      android:topRightRadius="0dp"
      android:bottomRightRadius="0dp"
      android:bottomLeftRadius="0dp" />
  <stroke
      android:width="1dp"
      android:color="#E3E3E1" />

  <solid android:color="@color/blanc" />

</shape>
Run Code Online (Sandbox Code Playgroud)

android border android-linearlayout

138
推荐指数
8
解决办法
24万
查看次数

适用于Android中的ImageButton中的图像

我的活动中有6个ImageButton,我通过我的代码设置图像(不使用xml).

我希望它们覆盖75%的按钮区域.但是,由于某些图像覆盖的区域较少,因此有些图像太大而无法适应图像按钮.如何以编程方式调整大小并显示它们?以下是截图

在此输入图像描述 下面是xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_marginBottom="5sp"
        android:layout_marginLeft="2sp"
        android:layout_marginRight="5sp"
        android:layout_marginTop="0sp"     >
   <LinearLayout
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal">
        <ImageButton          

            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:id="@+id/button_topleft"
        android:layout_marginBottom="5sp"
        android:layout_marginLeft="2sp"
        android:layout_marginRight="5sp"
        android:layout_marginTop="0sp"
            />
        <ImageButton
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:id="@+id/button_topright"
    android:layout_marginBottom="5sp"
        android:layout_marginLeft="2sp"
        android:layout_marginRight="5sp"
        android:layout_marginTop="0sp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal">

        <ImageButton
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:id="@+id/button_repeat"
    android:layout_marginBottom="5sp"
        android:layout_marginLeft="2sp"
        android:layout_marginRight="5sp"
        android:layout_marginTop="0sp"     
             />

              <ImageButton
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:id="@+id/button_next"
    android:layout_marginBottom="5sp"
        android:layout_marginLeft="2sp"
        android:layout_marginRight="5sp"
        android:layout_marginTop="0sp"     
             />

    </LinearLayout>    
   <LinearLayout
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal">

        <ImageButton
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:id="@+id/button_bottomleft"
    android:layout_marginBottom="5sp"
        android:layout_marginLeft="2sp" …
Run Code Online (Sandbox Code Playgroud)

android image scale imagebutton android-linearlayout

134
推荐指数
5
解决办法
22万
查看次数