Tag: android layout

如何消除焦点而不把焦点放在另一个控制上?

我喜欢我的UI是直观的; 每个屏幕都应该自然而不引人注目地引导用户进入应用的下一步。 除此之外,我努力使事情变得混乱和混乱。 开玩笑 :-) 我有三个TableRows,每个包含一个只读和不可调焦的EditText控件,然后在其右侧有一个button。 每个button启动相同的活动,但具有不同的参数。 用户在那里做出select,子活动结束,用用户的select填充适当的EditText。 这是经典的级联价值机制; 每个select都会缩小下一个select的可用选项等。因此,我将禁用每个下一行的两个控件,直到当前行上的EditText包含一个值。 我需要按照以下顺序执行以下两项操作之一: 点击一个button时,请立即移除焦点,而不要将焦点设置为不同的button 活动开始时,将焦点设置到第一个button 问题在子活动返回后出现; 被点击的button保持焦点。 回复:#1以上 – 似乎没有一个removeFocus()方法,或类似的东西 Re:上面的#2 – 我可以使用requestFocus()将焦点设置到下一行的button,并且在子活动返回之后工作,但由于某种原因,它在父活动的onCreate()中不起作用。 我需要在任何一个方向的UI一致性 – 在子活动完成后,或者每个button都获得焦点(取决于其在逻辑stream程中的位置,包括在任何select之前的第一个(且唯一的)活动button),则没有button具有焦点。

将UI元素的位置/大小设置为屏幕大小的百分比

我试图解决在创build布局时是否可以使用百分比位置/大小。 我想要的是这样的… ^ | | | 68% | | v Gallery (height equivalent of 16% total screen size) ^ | 16% v 我正在testing一个横向显示800×480实际像素的设备,目前我正在用以下命令强制它: <?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" > <Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="80px" android:layout_marginTop ="320px" /> </RelativeLayout> 显然,我不想硬编码固定的px单位,但我不能使用layout_marginTop 68%或0.68 (例如)。 我已经看过dp单元,但我不确定是否可以这样做。 我不得不承认UIdevise是我的一个弱点,所以任何build议都会受到感谢。 编辑:为了将来的参考,如果有人正在寻找一个类似的答案,继艾伦·摩尔的build议,我有以下工作正是我想要它… <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:background="@drawable/bground" android:layout_width="fill_parent" android:layout_height="fill_parent" > […]

渲染期间引发的exception:二进制XML文件行#-1:错误膨胀类<未知>

我试图在布局中包括checkbox,拖放后我得到这个错误: 渲染期间引发的exception:二进制XML文件行#-1:错误膨胀class<unknown> 。 xml文件: <?xml version="1.0" encoding="utf-8"?><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.nidhigupta.shopping2.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:id="@+id/textView" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New CheckBox" android:id="@+id/checkBox" android:layout_below="@+id/textView" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> </RelativeLayout> 请提供一步一步的解决scheme。 细节链接说: java.lang.NoSuchMethodError: android.graphics.drawable.VectorDrawable_Delegate.nCreateTreeFromCopy(JJ)J at android.graphics.drawable.VectorDrawable.nCreateTreeFromCopy(VectorDrawable.java) at android.graphics.drawable.VectorDrawable.access$400(VectorDrawable.java:204) at android.graphics.drawable.VectorDrawable$VectorDrawableState.createNativeTreeFromCopy(VectorDrawable.java:837) at android.graphics.drawable.VectorDrawable$VectorDrawableState.<init>(VectorDrawable.java:812) at android.graphics.drawable.VectorDrawable.mutate(VectorDrawable.java:268) at android.graphics.drawable.DrawableContainer$DrawableContainerState.addChild(DrawableContainer.java:817) at android.graphics.drawable.StateListDrawable$StateListState.addStateSet(StateListDrawable.java:329) at android.graphics.drawable.AnimatedStateListDrawable$AnimatedStateListState.addStateSet(AnimatedStateListDrawable.java:602) at […]

“包”android“中找不到属性”showAsAction“的资源标识符

我正在尝试更新我的Android应用程序,以更好地运行Honeycomb的平板电脑。 因此,我的目标是SDK的版本11(我的minSdkVersion = 4)。 这将蜂窝主题添加到我的应用程序,使其看起来更好。 但是,我无法访问我的菜单选项。 所以,我试图添加我的菜单项作为一个行动栏项目与以下在我的/ res / menu /文件夹中的文件: android:showAsAction="ifRoom|withText" 但是,我得到以下错误: “android”包中没有find属性“showAsAction”的资源标识符 我试图改变我的minSdkVersion号码到11,看看是否会工作,但没有运气。 有任何想法吗? 谢谢!

如何在android中包含布局内部布局

如何在Android中包含布局内部布局? 我正在创build共同的布局。 我想在另一个页面中包含该布局。

是否有可能使用VectorDrawable在button和TextViews使用android:DrawableRight?

当我在textview或imageview中使用VectorDrawable资产时,当使用“android:DrawableRight”/“android:DrawableEnd”/“android:DrawableStart”/“android:DrawableLeft”时,运行时崩溃。 该应用程序将编译罚款没有任何警告。 我在用 Gradle 1.5 支持库23.2('com.android.support:appcompat-v7:23.2.0') 我发现,虽然是我可以编程方式分配SVG的Java没有这样的崩溃。 TextView tv = (TextView) findViewById(R.id.textView); tv.setCompoundDrawablesWithIntrinsicBounds(null,null, getResources().getDrawable(R.drawable.ic_accessible_white_36px),null); (我怀疑这是23.2的支持库错误。) 但有没有可能使用drawableRight等SVG资产? 这是我的布局 <?xml version="1.0" encoding="utf-8"?> <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="au.com.angryitguy.testsvg.MainActivity"> <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableRight="@drawable/ic_accessible_white_36px" android:background="@color/colorPrimary" android:textColor="#FFFFFF" android:textSize="22sp" android:text="Hello World!"/> </RelativeLayout> 这是我的活动 package au.com.angryitguy.testsvg; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public […]

如何通过XML Drawable绘制圈子 – Android?

我正在尝试在android中的XML文件的帮助下绘制圆圈,但圆圈显示不正确。 下面的代码显示椭圆形。 如何在XML文件中创build圈子? <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF" android:angle="45"/> <padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" /> <corners android:radius="10dip" /> </shape> 任何帮助将是可观的。

两个TextViews并排,只有一个椭圆?

我想要两个TextView元素并排显示(在列表项中),一个alignment左边,一个右边。 就像是: |<TextView> <TextView>| ( |代表屏幕的四肢) 但是,左侧的TextView可能含有太长的内容,无法在屏幕上显示。 在这种情况下,我想要它的椭圆,但仍然显示整个正确的TextView 。 就像是: |This is a lot of conte…<TextView>| 我有很多尝试,使用LinearLayout和RelativeLayout ,唯一的解决scheme是使用RelativeLayout ,并将左边的TextView的marginRight大到足以清除正确的TextView 。 可以想像,这不是最佳的。 还有其他解决scheme吗? 最后, LinearLayout解决scheme: <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1" android:ellipsize="end" android:inputType="text" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="0" android:layout_gravity="right" android:inputType="text" /> </LinearLayout> 老, TableLayout解决scheme: <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="1" android:shrinkColumns="0" > <TableRow> <TextView android:id="@+id/title" […]

如何将LinearLayoutalignment到父级的中心?

我在这里看过很多类似的问题,但没有任何帮助。 我有不同的嵌套布局的层次结构,都有android:layout_width="fill_parent" ,最内部的布局有android:layout_width="wrap_content – 我需要在中心alignment(水平)。 ? 更新::我发现问题的原因 – 如果我把内置的LinearLayout放入RelativeLayout与android:layout_width="fill_parent" ,它仍然包装它的内容。 TableRow,但是,真的填满了屏幕。 <?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" > <FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <TableRow > <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppearance="?android:attr/textAppearanceLarge" /> </LinearLayout> </TableRow> </TableLayout> </FrameLayout> </LinearLayout>

如何在Android中使ListView透明?

如何在Android中使ListView透明? 背景android屏幕图像应该是可见的。