Tag: android layout

Android – 如何设置所有屏幕的背景颜色?

我一直在学习Android,到目前为止,我一直专注于function,但现在我开始使用布局。 我想知道什么是维护字体和颜色样式的最佳做法。 我做了一个colors.xml文件,我用它来改变button等单独元素的颜色,但我不确定Android是如何让开发人员组织它们的样式的。 例如,我希望所有屏幕都具有相同的背景颜色。 我怎么做? 是我需要为每个活动布局xml指定的东西吗? 或其他地方? 我如何完成它? 谢谢!

在导航抽屉中禁用暗淡的淡入淡出

有没有办法在Android中的导航抽屉视图中禁用背景视图的暗淡的影响?

DialogFragment在Android中的位置

我有一个DialogFragment来显示一个像Popup屏幕的View 。 该窗口始终显示在屏幕的中间。 有没有办法设置DialogFragment窗口的位置? 我查看了源代码,但是还找不到任何东西。

所有Android UI对象的getHeight返回0

我正在构build一个UI,它在XML中都是静态定义的。 所有的地方都有重量,虽然看起来不错,但我想看看事情确实拥有合适的高度。 问题是,不pipe我在哪里调用.getHeight()我的格式布局我得到0.我尝试在onCreate()和onStart()。 一样。 也适用于所有UI对象。 任何想法? package com.app.conekta; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.Window; import android.widget.Button; import android.widget.FrameLayout; import android.widget.Toast; public class Conekta extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override public void onStart() { super.onStart(); } @Override […]

Xml命名空间声明:自动replace包名

我有一个Android项目与多个生成目标(使用ant)。 为了testing的目的,这些构build目标都有不同的包名称(所以我的包名称是com.mycompany.myapp用于发布版本,com.mycompany.myapp.test用于testing版本)。 除了当涉及到布局文件中的自定义xml命名空间时,这大部分工作得很好。 所以这: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res/com.mycompany.myapp" /> 只要包名被com.mycompany.myapp.testreplace就会停止工作。 因此,我必须在预编译期间每次replacecom.mycompany.myapp值。 而且由于所有这些文件都应该在vcs中,并且不应该每当一个人切换configuration并且它们合并时都发生冲突,所以我必须将布局文件移动到特定的configuration文件夹中,它们看起来像: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res/@CONFIG.PACKAGENAME@" /> 现在这些文件存储在vcs中,@ CONFIG.PACKAGENAME @在预编译过程中被replace,然后将文件从./config/file.xml复制到./res/layout/file.xml。 这是非常不方便的,并不能很好地扩展(我不能想象在构build脚本中提到每个像50个文件)。 所以我的问题是:是否有一种方法来自动使用名称空间声明中的当前包名称? 或者至less是修改布局文件(或生成文件?),以便我不必每次更改包名称时都要replacecom.mycompany.myapp。

无法调整ScrollView中的RelativeLayout来填充整个屏幕

我有一个奇怪的问题,我不知道如何解决。 我有一个ScrollView内的RelativeLayout,这个scrollView的高度设置为fill_parent。 那么RelativeLayout也是如此。 尽pipe如此,内容并没有填满整个屏幕,而只是到了这个RelativeLayout中最后一个布局的wrap_content。 这是我的代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res/com.pontai" android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/relativeLayout3" android:layout_alignParentTop="true" android:layout_alignRight="@+id/relativeLayout5" android:layout_marginTop="5dp" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="How much points you have here:" android:textAppearance="?android:attr/textAppearanceSmall" /> <TextView android:id="@+id/textViewTotalPoints1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="120" android:textAppearance="?android:attr/textAppearanceMedium" /> </LinearLayout> <RelativeLayout android:id="@+id/relativeLayout4" […]

Android活动指标?

我怎样才能在Android中显示一个活动指标? 有没有Android库给定的方法? 如果不是,请让我知道用于显示Android中活动指示器的技巧。

指定的孩子已经有一个父母。 您必须首先调用子对象的父对象的removeView()

我创build这个post,因为我是新手,我需要一点帮助。 我正在做一个关于你的名字的应用程序,它会返回“你好(你放的名字)”。 但是,我按下button后,我得到的错误“指定的孩子已经有一个父母,你必须首先调用孩子的父母removeView() MainActivity.java package com.example.holaamigos; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.*; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { public final static String EXTRA_SALUDO = "com.example.holaamigos.SALUDO"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final EditText txtNombre = (EditText)findViewById(R.id.TxtNombre); final Button btnHola = (Button)findViewById(R.id.BtnHola); btnHola.setOnClickListener(new OnClickListener() { @Override […]

如何在Google地图应用中将Android工具栏菜单/图标alignment到左侧?

以下是Google地图工具栏的屏幕截图。 正如你所看到的图标是左alignment,而不是右(默认行为)。 我已经尝试添加android:layout_gravity =“左”和android:gravity =“左”到工具栏,但它没有工作。 也尝试添加一个内部的LinearLayout(具有相同的重力值)的工具栏,但也没有工作。 有任何想法吗? 我希望能够使用工具栏小部件的常规Android菜单,而不是从零开始重新创build所有的东西。

Android:以编程方式从Java代码填充微调器

你如何从Java代码编程填充微调? 我在这样的布局中有一个微调: <Spinner android:id="@+id/consultation_deseases" android:layout_width="@dimen/bigSpinnerWidth" android:layout_height="@dimen/bigSpinnerHeight" android:prompt="@string/disease_prompt" /> 用java代码,我需要创build适配器并添加项目。