Tag: android layout

ClassCastException android.widget.FrameLayout $ LayoutParams to android.support.v4.widget.DrawerLayout $ LayoutParams

我正在为Android导航抽屉工作。 根据我的要求,我要显示导航抽屉中的项目的gridview和listview。 我在布局xml文件中创build了一个linearLayout,并将两个小部件(网格视图和Listview)放置在LinearLayout中。 当我运行该文件时出现以下错误: java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.navigationdrawer3 / com.example.navigationdrawer3.MainActivity}:java.lang.ClassCastException:android.widget.FrameLayout $ LayoutParams不能转换为android.support.v4。 widget.DrawerLayout $的LayoutParams 下面是我的java,logcat和NavigationDrawer布局文件: MainActivity.java public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ListView mDrawerList; private ActionBarDrawerToggle mDrawerToggle; private CharSequence mDrawerTitle; //@SuppressWarnings("unused") private CharSequence mTitle; private String[] mGalaxyTitles; private GridView mDrawerGrid; private LinearLayout mDrawerLinear; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = […]

Android的布局与9补丁背景打破

更新我的背景以使用9修补图像时遇到此问题。 在不同的屏幕上,使用不同大小的相同图像的布局很好,但是当我将图像更改为9补丁时,它会神秘地破坏整个布局。 以前的布局看起来像这样: 原始布局http://onik.org/android/layoutOk.png 。 当更改为9-patch时: 9-Patch image http://onik.org/android/layoutError.png 。 XML文件保持不变,只是PNG文件被更改。 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg"> <TextView android:text="@string/title" android:id="@+id/login_title" android:layout_width="fill_parent" android:layout_height="40px" android:textSize="30px"> </TextView> <View android:id="@+id/login_underline" android:layout_width="wrap_content" android:layout_height="2px" android:background="#aaaaaa"> </View> <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:stretchColumns="1" android:gravity="center" android:paddingLeft="10px" android:paddingRight="10px"> <TableRow> <TextView android:id="@+id/login_usernameLabel" android:text="@string/login_usernameLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="5px"> </TextView> <EditText android:text="" android:id="@+id/login_username" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textEmailAddress" […]

Android Studio Google Map V2片段呈现

我试图在Android Studio中编写Google Map V2的testing演示。 我遵循Androidhive Google Map V2的每一个步骤,或者更好,我认为我需要。 我使用相同的layout_main.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" > <fragment android:id="@+id/map" android:name="com.google.android.gms.maps.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout> 但我总是有相同的渲染问题: 渲染问题 <fragment>标签允许布局文件在运行时dynamic地包含不同的布局。 在布局编辑时,要使用的特定布局未知。 您可以在编辑布局时select您想要预览的布局… 我完全不知道有什么问题。 我忘记了什么吗? 我只需要在build.gradle中添加Google服务 compile 'com.google.android.gms:play-services:4.4.52' 我复制了演示中的清单,并更改了API密钥。

Androidbutton具有不同的背景颜色

我想用selector-xml-file来改变button的背景颜色。 我的方法基本上是从本页底部的例子: http : //developer.android.com/guide/topics/resources/color-list-resource.html 我有一个res / color / button_text.xml如下所示: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:color="#ffff0000"/> <!– pressed –> <item android:state_focused="true" android:color="#ff0000ff"/> <!– focused –> <item android:color="#ff000000"/> <!– default –> </selector> 和我的布局包含以下代码: <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/button_text" **android:background="@color/button_text"** /> (**只是在那里向你展示,我使用android:背景,而不是android:textcolor) 此代码崩溃。 它说:“二进制XML文件行#4标签需要'drawable'属性或子标签定义drawable。但是,如果我尝试使用android:textColor在上面的链接描述,它工作得很好,所以它必须是背景问题。如果没有必要的话,不想创build9patch-png(基本上我只需要一个“可点击的”矩形,所以我使用带有彩色背景的button)

“_Problem Loading Widget”消息

当加载一个小部件,如果它找不到资源或它说问题加载小部件。 就这样! 惊人! 这个消息仍然在主屏幕上,甚至不知道加载时遇到了哪个小部件。 我想通过反复试验找出它,但是我想知道是否有任何地方在发生这种情况时find错误信息。 Android会在哪里说加载小部件有什么问题,甚至哪个小部件加载失败?

在android中如何在类文件中以编程方式设置导航抽屉标题图像和名称?

在Android Studio 1.4.1中,我创build了一个新的导航抽屉项目,这是默认的。我的问题是在这个项目中有导航标题图像和名称的nav_header_main.xml文件。 我希望这个图像和名称应该在我的主要类活动中以编程方式设置。 如何做到这一点,我尝试了很多,但应用程序崩溃。 nav_header_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="match_parent" android:id="@+id/headerView" android:layout_height="@dimen/nav_header_height" android:background="@drawable/side_nav_bar" android:gravity="bottom" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:theme="@style/ThemeOverlay.AppCompat.Dark"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="@dimen/nav_header_vertical_spacing" android:src="@android:drawable/sym_def_app_icon" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="@dimen/nav_header_vertical_spacing" android:text="Android Studio" android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="android.studio@android.com" /> </LinearLayout> activity_main.xml中 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" […]

如何使用可与图像一起绘制的形状?

我有这个困难,我的LinearLayout有圆angular和背景图像。 我知道我可以通过使用形状可绘制XML来实现圆angular,但是如果我将可绘制的形状作为我的LinearLayout的背景与android:background=@drawable/rounded_corner那么我不能指定任何图像作为背景。 我怎么能得到我的LinearLayout背景图像的圆angular? 任何帮助,将不胜感激。 谢谢!

在android中使用数据绑定在android:src中为ImageView设置drawable资源ID

我试图设置可绘制的资源ID到android:使用数据绑定ImageView的src 这是我的目标: public class Recipe implements Parcelable { public final int imageResource; // resource ID (eg R.drawable.some_image) public final String title; // … public Recipe(int imageResource, String title /* … */) { this.imageResource = imageResource; this.title = title; } // … } 这是我的布局: <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <data> <variable name="recipe" type="com.example.android.fivewaystocookeggs.Recipe" /> </data> […]

在Android应用程序中集成video文件作为应用程序背景

我需要使用video作为我的背景。 首先我把video文件放在drawable文件夹中,并在main.xml中作为LinearLayout背景调用。 但是在运行应用程序时,我只看到一个黑屏。 然后我试图使用VideoView并将其称为如下: <VideoView android:id="@+id/video" android:layout_width="320px" android:layout_height="240px" android:layout_gravity="center" android:background="@raw/hp"/> 在我的活动文件中,我用下面的代码片段调用它: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); VideoView video=(VideoView) findViewById(R.id.video); video.start(); } 但是我还没有收到video文件。 我的主要build议是使用泡泡video作为背景,并在其上放置两个泡泡button,并给用户一种水景画面的感觉。 谁能帮我? 此外,我想从res文件夹中使用的video文件。 不是从SD卡或任何外部媒体文件夹。

值等于dimens.xml中的match_parent或fill_parent?

基于XML Attributes部分,我在我的dimens.xml指定了以下dimens.xml : <dimen name="match_parent">-1dp</dimen> <dimen name="main_left_menu_user_account_width">@dimen/match_parent</dimen> <dimen name="main_left_menu_user_account_height">@dimen/match_parent</dimen> 然后我在我的布局中使用这两个维度: <ImageView android:id="@+id/userAccountImage" android:background="@drawable/user_account" android:layout_width="@dimen/main_left_menu_user_account_width" android:layout_height="@dimen/main_left_menu_user_account_height" /> 然后,当我预览到Graphical Layout ,它抱怨: 您必须提供一个layout_width属性。 您必须提供一个layout_height属性。 其实我可以在dimens.xml定义一个等于match_parent的值吗? 更新: 我也试过,但预览仍然抱怨: <dimen name="main_left_menu_user_account_width">-1dp</dimen> <dimen name="main_left_menu_user_account_height">-1dp</dimen> 我成功地使用了wrap_content ( Graphical Layout根本不抱怨): <dimen name="wrap_content">-2dp</dimen> <dimen name="main_right_menu_width">@dimen/wrap_content</dimen> <dimen name="main_right_menu_height">@dimen/wrap_content</dimen>