标签: android-linearlayout

如何更改Android中进度条的颜色? - (我尝试了一种方式,但它不起作用)

我使用以下代码为我的活动添加了一个进度条:

<LinearLayout
    android:id="@+id/linlaHeaderProgress"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:visibility="gone" >

    <ProgressBar
        android:id="@+id/pbHeaderProgress"
        android:indeterminateOnly="true"
        android:keepScreenOn="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ProgressBar>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

然后我称之为:

 progressbar = (LinearLayout) findViewById(R.id.linlaHeaderProgress);
 progressbar.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)

将显示进度条,我想更改它的颜色.默认情况下,进度条以灰色显示.这是我试图改变颜色:

我在drawables文件夹中创建了一个xml文件,并将其命名activityindicator.xml 为此xml的内容为:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/secondaryProgress">


        <color android:color="#f58233" />
    </item>
    <item android:id="@android:id/progress">

        <color android:color="#f58233" />
    </item>

</layer-list>
Run Code Online (Sandbox Code Playgroud)

我将布局文件更改为:

<LinearLayout
    android:id="@+id/linlaHeaderProgress"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:progressDrawable="@drawable/activityindicator"
    android:orientation="vertical"
    android:visibility="gone" >

    <ProgressBar
        android:id="@+id/pbHeaderProgress"
        android:indeterminateOnly="true"
        android:keepScreenOn="true"
        android:progressDrawable="@drawable/activityindicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ProgressBar>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这就是我尝试过的,但颜色并没有改变.谁能告诉我我做错了什么?

我正在使用Lollipop版本.

xml android android-linearlayout progress-bar android-drawable

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

ListView与LinearLayout

我正在写一个水平的电视视图,类似于你知道的tivo系统和类似的.对于每个频道,在接下来的6个小时左右有一行节目,其宽度与播放时间成比例.

我的想法是为每一行编写一个自定义小部件,并将它们堆叠在一起.这应该允许我以递增方式加载数据,而不是使用一个大的自定义视图.但是,我仍然需要页面顶部的向前/向后按钮,单击时更新所有行.

现在我不确定是否应该将这些视图放在ListView或LinearLayout中.

我收集了以下优点和缺点:

  • 列表显示
    • 优点
      • 内存高效 - 重新隐藏视图
      • 似乎所有人都可以在Android社区中使用它.
      • 在更新行时可能更容易使它变得懒惰,因此需要更少的CPU.
    • 缺点
      • 矫枉过正 - 我不会使用它提供的大部分功能
      • 附加clickListeners可能稍微困难一些.
  • 的LinearLayout
    • 优点
      • 简单易用.你有什么期望的.
    • 缺点
      • 我还没有看到它用于任何长列表.
      • 也许它慢一点?

ListView的"似乎被所有人使用"的论点还包括"Master"Twitter应用程序,Google用它来炫耀"好的Android设计".他们似乎也没有使用它的大部分功能.

你有这方面的工作经验吗?在阅读文档时,我是否遗漏了任何建议?

performance android listview android-linearlayout

16
推荐指数
1
解决办法
3286
查看次数

Android模拟器不会向下滚动

我正在创建一个布局如下,当我在AVD中模拟它时.它不会向下滚动以查看折叠下方的内容.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_height="wrap_content"
    android:layout_width="wrap_content">

    <TextView android:text="@string/UserFormWelcome"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:textSize="20px" android:gravity="center" />

    <TextView android:text="@string/name" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:textStyle="bold"
        android:paddingTop="20px" android:paddingLeft="10px" />


    <TableLayout android:layout_height="wrap_content"
        android:layout_width="wrap_content">

        <TableRow android:layout_height="wrap_content"
            android:layout_width="match_parent" android:paddingTop="20px">

            <TextView android:text="@string/firstname"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:width="100px" android:paddingLeft="10px" />

            <EditText android:id="@+id/LastName" android:width="200px"
                android:layout_width="fill_parent" android:layout_height="wrap_content" />

        </TableRow>

        <TableRow android:layout_height="wrap_content"
            android:layout_width="match_parent">

            <TextView android:text="@string/lastname"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:paddingLeft="10px" />

            <EditText android:id="@+id/LastName" android:width="200px"
                android:layout_width="fill_parent" android:layout_height="wrap_content" />

        </TableRow>

    </TableLayout>


    <TextView android:text="@string/dob" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:textStyle="bold"
        android:paddingTop="20px" android:paddingLeft="10px" />

    <TableLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:stretchColumns="3"
        android:paddingTop="20px" android:paddingLeft="10px">
        <TableRow>
            <TextView android:text="@string/date" android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android scroll tablelayout android-layout android-linearlayout

16
推荐指数
1
解决办法
8480
查看次数

向LinearLayout添加多个视图的最快方法是什么?

我有一个LinearLayout已经包含几个元素的视图.我想以编程方式添加更多视图.因为这是在一个内部ScrollView,一切都将滚动.

所以我要做的就是浏览我的列表,并将自定义View的新实例添加到其中.该自定义视图会扩展XML布局并添加一些方法.

这种方法效果很好.问题是它的速度非常慢,即使没有任何疯狂的代码......一个包含10个项目的列表需要大约500ms才能实例化.从用户体验的角度来看,这很难被接受.

我的问题是,这是正确/最好的方法吗?虽然"R.layout.my_list_item"非常简单,但Android似乎需要花费大量时间来夸大布局.我想知道是否有办法可以为其他视图重用"膨胀"布局,有点缓存更复杂的解析?

我已经尝试用ListView(和适配器和包装器)这样做,它似乎更快.问题是我不能用简单的ListView; 我的布局比一个简单的列表更复杂(它LinearLayout本身包含额外的自定义图标,并且在它被包装之前它有另一个具有更多视图的父级ScrollView).

但是有没有办法为LinearLayout使用适配器?这会比尝试自己添加视图更快吗?

任何帮助表示赞赏.我想更快地做到这一点.

代码如下.

主要活动:

// The LinearLayout that will contain everything
lineList = (LinearLayout) findViewById(R.id.lineList);

// Add a lot of items for testing
for (int i = 0; i < 10; i++) {
    addListItem("Item number " + i);
}

protected void addListItem(String __title) {
    MyListItem li;
    li = new MyListItem(this);
    li.setTitle(__title);
    lineList.addView(li);       
}
Run Code Online (Sandbox Code Playgroud)

MyListItem:

public class MyListItem extends RelativeLayout {

    protected TextView …
Run Code Online (Sandbox Code Playgroud)

layout android view inflate android-linearlayout

16
推荐指数
1
解决办法
6592
查看次数

LinearLayout中的中心按钮

我有这个布局:

<?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="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@android:color/darker_gray"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/mon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="10"
        android:text="M\nO\nN" />

    <CheckBox
        android:id="@+id/cbmon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="10" />

    <TimePicker
        android:id="@+id/timePicker1mon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="40" />

    <TimePicker
        android:id="@+id/timePicker2mon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="40" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@android:color/white"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/mon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="10"
        android:text="T\nU\nE" />

    <CheckBox
        android:id="@+id/cbtue"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="10" />

    <TimePicker
        android:id="@+id/timePicker1tue"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="40" />

    <TimePicker
        android:id="@+id/timePicker2tues"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="40" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" …
Run Code Online (Sandbox Code Playgroud)

android android-linearlayout

16
推荐指数
2
解决办法
3万
查看次数

为什么我的RelativeLayout中的ImageView顶部和底部会出现空白区域?

我使用relativelayout覆盖图像.到目前为止我所测试的所有屏幕尺寸(从2.7到10.1英寸)我总是在我的图像上方获得空白区域.在我的IDE中,我总是看到我的relativelayout导致了图像顶部和底部的额外空间.

这是为什么?我已将所有高度属性设置为wrap_content甚至添加了adjustViewBounds属性.

注意:您应该知道我的图像尺寸更大,这意味着会有某种缩放.

谢谢你的提示!

这是代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"
    android:orientation="vertical" >

<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:orientation="vertical" 
    android:focusable="true"
android:focusableInTouchMode="true">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:text="@string/bgf"
    android:textColor="#000000"
    android:textSize="25sp" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:adjustViewBounds="true"
        android:paddingRight="5dp"
        android:paddingLeft="5dp"
        android:paddingBottom="5dp"
        android:layout_gravity="center_horizontal"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/cde"
        android:contentDescription="@string/cde" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:layout_gravity="center_horizontal"
        android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
        android:src="@drawable/fgh"
        android:contentDescription="@string/abc" />

</RelativeLayout>


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

android android-linearlayout android-relativelayout

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

如何制作zoomable scrollview?

在我的Android应用程序中,我需要创建可缩放的活动.我在这里找到了用于缩放线性布局的有用代码.但在我的应用程序中,几个活动以scrollview开头,此代码无法识别scrollview.如何为可滚动活动进行捏缩放?这是我的布局之一.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollViewZoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >

<LinearLayout
    android:id="@+id/wd_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:orientation="vertical" >

    <!-- Start Circle -->

    <TableRow
        android:id="@+id/row_circl1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:background="@color/purple_color" >

        <RelativeLayout
            android:id="@+id/circle_layout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white_color" >

            <ImageView
                android:id="@+id/img_engin_circle1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:background="@drawable/circle_engin_bg"
                android:contentDescription="TODO" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/circle_layout2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white_color" >

            <ImageView
                android:id="@+id/img_engin_circle2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:background="@drawable/circle_engin_bg"
                android:contentDescription="TODO" />
        </RelativeLayout>
    </TableRow>

    <TableRow
        android:id="@+id/row_name_circle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginTop="30dp" >

        <RelativeLayout
            android:id="@+id/circle_name_layout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="-15dp"
            android:background="@color/white_color" >

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

android android-layout android-linearlayout android-scrollview android-activity

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

线性布局的选框效果

我正在尝试对布局实现选框效果,以帮助它从右侧内侧向左侧内侧滚动/动画,就像自动收报机视图一样.

从以下两个链接中,您可以获得更多知识,就像股票市场通过以循环常量方式显示值来更新用户一样.

1)http://www.sify.com/finance/livemarkets/

2)http://terminal.moneycontrol.com/index.php?wl=indices

为此,我已经实现了下面的代码,使其有些类似.

public class HorizonalSlideActivity extends Activity
{
    private LinearLayout horizontalOuterLayout;
    private HorizontalScrollView horizontalScrollview;
    private int scrollMax;
    private int scrollPos = 0;
    private TimerTask scrollerSchedule;
    private Timer scrollTimer = null;
    private ScrollAdapter adapter = null;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.horizontal_layout);

        adapter = new ScrollAdapter(HorizonalSlideActivity.this);

        horizontalScrollview = (HorizontalScrollView) findViewById(R.id.horiztonal_scrollview_id);
        horizontalScrollview.setOnTouchListener(new OnTouchListener()
        {
            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                return false;
            }
        });
        horizontalOuterLayout = (LinearLayout) findViewById(R.id.horiztonal_outer_layout_id);
        horizontalTextView = (TextView) findViewById(R.id.horizontal_textview_id);
        horizontalScrollview.setHorizontalScrollBarEnabled(false); …
Run Code Online (Sandbox Code Playgroud)

android marquee horizontalscrollview android-animation android-linearlayout

16
推荐指数
2
解决办法
2994
查看次数

Android上的透明LinearLayout

我有以下布局:

在此输入图像描述

我想透明透明的transparent_layout,但我不能这样做.

已经尝试使用颜色以编程方式设置背景:Color.TRANSPARENT但似乎它不起作用.

我使用Android 2.3.3 SDK与SherlockActionBar.

有没有办法将该布局设置为透明?

android transparent android-linearlayout

15
推荐指数
3
解决办法
6万
查看次数

Android 二进制布局膨胀异常:ClassNotFoundException:在路径上找不到类“android.view.layout”:

我的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        card_view:cardCornerRadius="4dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <FrameLayout
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/profilePic"
                    android:layout_width="96dp"
                    android:layout_height="96dp"
                    android:layout_gravity="center_horizontal"
                    android:src="@drawable/avatar" />

            </FrameLayout>

            <RelativeLayout
                android:id="@+id/user_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/header">

                <ImageView
                    android:id="@+id/divider"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:src="@color/contentDividerLine" />

                <TextView
                    android:id="@+id/username"
                    style="@style/Base.Widget.AppCompat.Button.Borderless"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="bottom"
                    android:drawablePadding="5dp"
                    android:padding="8dp"
                    android:text="Name"
                    android:textColor="@color/Black" />


            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/user_view">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:src="@color/contentDividerLine" />

                <TextView
                    android:id="@+id/email"
                    style="@style/Base.Widget.AppCompat.Button.Borderless"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="bottom"
                    android:drawablePadding="5dp"
                    android:padding="8dp"
                    android:text="Email" …
Run Code Online (Sandbox Code Playgroud)

java android android-layout android-linearlayout

15
推荐指数
3
解决办法
8891
查看次数