Tag: android layout

AppCompat_v7工具栏作为操作栏不会显示菜单中的“始终”操作,但API工具栏会显示

经过2天的努力,新API 21工具栏和appCompat_v7,我觉得我发现了一个错误。 如果你在你的菜单上有两个动作,像这样: <item android:id="@+id/action_test" android:showAsAction="always" android:icon="@drawable/ic_launcher" android:title="@string/action_settings"/> <item android:id="@+id/action_settings" android:orderInCategory="100" android:showAsAction="never" android:title="@string/action_settings"/> 和一个像这样定义的appCompat工具栏: <RelativeLayout 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: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="com.example.toolbar.MainActivity" > <android.support.v7.widget.Toolbar android:layout_width="match_parent" android:layout_height="52dp" android:id="@+id/toolbar"> </android.support.v7.widget.Toolbar> </RelativeLayout> 充气后(或设置setSupportActionBar方法) Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar); toolbar.setTitle("esurance"); setSupportActionBar(toolbar); 你会得到没有你的动作图标的工具栏菜单,它会显示在溢出菜单上。 但是,如果您使用API​​ 21的工具栏类,它将显示您在菜单布局中定义的操作… <Toolbar android:layout_width="match_parent" android:layout_height="52dp" android:id="@+id/toolbar"> </Toolbar> 也许我在这里错过了一些东西,但到目前为止,我一直无法使用appCompat在溢出菜单之外显示操作。 任何帮助,将不胜感激。

Android的Google地图片段在xml中。 我得到“意外的命名空间前缀”

我正在尝试学习android,并按照关于如何使用Google Maps API V.2的说明进行操作。 不过,有关如何在developers.google.com上find映射初始状态的说明,build议在xml文件中定义一个名称空间,在本例中为“map”。 下面的xml代码给出错误“意外的命名空间前缀”地图“ ”。 试图在fragment标签中定义xmlns:map给出了与“xmlns”相同的错误。 我明显缺less一些基本的XML知识在这里,有人可以帮我吗? <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:map="http://schemas.android.com/apk/res-auto" <!– Definition –> android:layout_width="match_parent" android:layout_height="match_parent"> <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment" map:cameraBearing="112.5"/> <!– PROBLEM –> </RelativeLayout>

如何禁用布局内的所有视图?

例如,我有: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/backbutton" android:text="Back" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <LinearLayout android:id="@+id/my_layout" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/my_text_view" android:text="First Name" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:id="@+id/my_edit_view" android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <View …/> <View …/> … <View …/> </LinearLayout> </LinearLayout> 有没有办法禁用(setEnable(false))LinearLayout my_layout内的所有元素?

创build一个Android智能应用程序横幅

是否有类似于iOS 6智能应用横幅的Android设备的解决scheme? 这里是智能应用横幅的代码 <meta name="apple-itunes-app" content="app-id=311507490, affiliate-data=partnerId=30&siteID=k1CkFsOh4nQ"/>

在Android中缩放图像以填充整个ImageView

我想缩放一个图像,占据整个ImageView的大小。 这与使用scaleType=fit_center差别scaleType=fit_center因为如果图像纵横比与ImageView纵横比不完全匹配, fit_center会在图像周围留下条带。 相反,我希望图像能够居中放大并完全填充封闭的视图,并将任何多余的部分切掉。 我能够通过在onCreate()期间计算自己的自定义图像matrix来实现这一点: final Display display = getWindowManager().getDefaultDisplay(); final float screenWidth = display.getWidth(); final float screenHeight = display.getHeight(); final float imageWidth = splashView.getDrawable().getIntrinsicWidth(); final float imageHeight = splashView.getDrawable().getIntrinsicHeight(); final Matrix splashMatrix = new Matrix(); final float scale = Math.max(screenHeight/imageHeight,screenWidth/imageWidth); splashMatrix.postScale( scale, scale ); splashView.setImageMatrix(splashMatrix); 这工作正常,但似乎必须有一个更容易。 有谁知道在ImageView中放大图像的方法,同时保留图像的纵横比并完全填充ImageView? (注意:在我的情况下,我的ImageView占用了全屏幕,所以我使用getWindowManager().getDisplay()来查找所需的图像大小。不能使用splashView.getWidth() / getHeight()因为视图hasn还没有布置,没有一个大小)

如何做新的PlayStore视差效果

有谁知道我怎样才能实现新的视差滚动效果 – 当你在PlayStore上打开一个应用程序并尝试向下滚动时,你可以看到效果,内容超越了顶部图像。 我怎样才能做到这一点?

如何以编程方式在自定义标题栏上设置背景颜色渐变?

那里有很多教程和关于实现自定义标题栏的问题。 然而,在我的自定义标题栏中,我有一个自定义的背景渐变,我想知道如何在我的代码中dynamic地设置它。 这是我的自定义标题栏被调用的地方: requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.foo_layout); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar); 这是我的custom_title_bar : <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@layout/custom_title_bar_background_colors"> <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/title_bar_logo" android:gravity="center_horizontal" android:paddingTop="0dip"/> </LinearLayout> 正如你所看到的,线性布局的背景是由这个家伙定义的: <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#616261" android:endColor="#131313" android:angle="270" /> <corners android:radius="0dp" /> </shape> 我想要做的是在我的代码中dynamic地设置这些渐变颜色。 我不想像现在这样在我的XML文件中对它们进行硬编码。 如果您有更好的方式设置背景渐变,我愿意接受所有的想法。 先谢谢你!!

在RelativeLayout中的TextView水平中心

在我的应用程序屏幕上,我想显示标题为水平居中。 我尝试使用下面的布局XML代码 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginTop="10dip" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="Connections" /> </RelativeLayout> 谢谢

是否有可能在微调项目custom_style.xml中指定多个重力值?

我有textview.xml,这是spinners的项目样式。 <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="left|center_horizontal" android:textSize="18sp"> </TextView> 我知道可以同时指定(Gravity.LEFT | Gravity.CENTER_HORIZONTAL) ,但是在不起作用的xml中,文本仅移动到左侧。

Android:如何设置Toast文本的颜色

我使用以下代码作为if语句的结果显示吐司消息: Toast.makeText(getBaseContext(),“请input价格”,Toast.LENGTH_SHORT).show(); 它在白色背景上显示为白色文字,因此无法阅读! 我的问题是,我怎样才能改变吐司文字的颜色?