标签: android-xml

无法在自定义适配器中使用LayoutInflater

我正在考虑编写一个自定义适配器来填充列表视图,每行3个textview.我已经找到了相当多的示例代码来执行此操作,但看起来最好的代码是:http://www.anddev.org/custom_widget_adapters-t1796.html

经过一些小的调整来修复最新的Android SDK的一些编译器问题后,我让它运行,只是为了得到异常:

ERROR/AndroidRuntime(281):java.lang.UnsupportedOperationException:AdapterView不支持addView(View,LayoutParams)

所以我做了很多研究,发现了很多可能的原因和解决方法.这些都没有改变.我的适配器代码目前是:

public class WeatherAdapter extends BaseAdapter {

    private Context context;
    private List<Weather> weatherList;

    public WeatherAdapter(Context context, int rowResID,
                        List<Weather> weatherList ) { 
        this.context = context;
        this.weatherList = weatherList;
    }

    public int getCount() {                        
        return weatherList.size();
    }

    public Object getItem(int position) {     
        return weatherList.get(position);
    }

    public long getItemId(int position) {  
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) { 
        Weather weather = weatherList.get(position);

        //LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LayoutInflater inflater = LayoutInflater.from(context); …
Run Code Online (Sandbox Code Playgroud)

android listview android-layout android-xml android-adapter

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

Android:默认XML编辑器不再打开[不支持的内容类型错误]

我已经使用Eclipse在Android中开发应用程序已有一段时间了.我最近将Android SDK平台更新到3.0,API 11.现在我无法通过双击打开LayoutManifest.xml或Layout文件夹中的任何其他XML文件.

当我双击任何XML文件(如main.xml/strings.xml)时,我收到"不支持的内容类型"错误. http://www.freeimagehosting.net/uploads/67e93ddb8a.png

有什么方法可以解决这个问题吗?

PS:如果我打开带有"打开方式 - >文本编辑器"的xml文件,它会打开,但是我无法看到main.xml的布局以及strings.xml和androidmanifest.xml的相应GUI http:// www.freeimagehosting.net/uploads/f537965b68.png

xml eclipse android android-layout android-xml

8
推荐指数
2
解决办法
3725
查看次数

在运行时创建,存储和扩展自定义布局

我正在尝试找到解决以下问题的方法.我工作的应用程序要求用户通过自定义UI构建器生成自定义UI(简单小部件的布局).因此,用户可以在画布上堆叠小部件(大多数图像,但也包括TextViews和EditText),移动它们等等.必须将UI存储在数据库中以备将来使用.因此,应该有一些加载和扩充此UI的机制.这是主要问题.

我的第一个想法是依靠标准的Android布局机制.不幸的是,LayoutInflater使用编译成二进制形式的XML.据我所知,在运行时不可能将XML字符串编译成二进制表示.

有没有人有这种问题的经验?有什么建议?

android android-widget android-layout android-xml

8
推荐指数
1
解决办法
3537
查看次数

如何从参考格式类型的attr获取字符串?

我有我attr.xml指定的自定义文档declare-styleable:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <declare-styleable name="EditTextValidateablePreference">
        <attr name="errorMessage" format="reference" />
    </declare-styleable>

</resources>
Run Code Online (Sandbox Code Playgroud)

然后在布局我设置:

<com.xx.yy.EditTextValidateablePreference
    ...
    ns:errorMessage="@string/validation_email_mail_server_invalid"
    />
Run Code Online (Sandbox Code Playgroud)

EditTextValidateablePreference.class我得到它:

    String validatorErrorMessage = attrs.getAttributeValue(PREFERENCE_NS, "errorMessage");
Run Code Online (Sandbox Code Playgroud)

validatorErrorMessage 有一个像这样的值: @2131099700

如何获取其整数值以将其用于:

context.getResources().getString(messageId)
Run Code Online (Sandbox Code Playgroud)

谢谢 !

android android-layout android-xml

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

为什么Android布局中的Fragment元素用小写'f'编写?

所有其他元素都以大写字母开头,如RelativeLayout,TextView等.

是否有一个特殊的原因可以将Fragment元素用作<fragment ... />代替<Fragment ... />

android android-layout android-xml android-fragments

8
推荐指数
1
解决办法
309
查看次数

如何在自定义应用程序中使用Android Stock Calendar中的视图(月,日,周)

在Google Stock Android日历中存在多个视图(月,周,议程,周),从Google Android Sources Repositories下载的源代码具有相同的应用程序,通过探索代码,命名包com.android.calendar具有负责呈现这些活动的主视图:

在此输入图像描述

通过努力解决代码,我使用了两个包com.android.calendar.month,com.android.calendar但无法实现我的目标,这是我使用的示例:

在此输入图像描述

以及主要的以下代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
Run Code Online (Sandbox Code Playgroud)

这是我的xml代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/month"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:paddingTop="1dip"
    android:background="@null">

    <TextView android:id="@+id/month_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="10dip"
        android:visibility="gone"
        style="@style/MonthView_MiniMonthLabel" />

    <include android:id="@+id/day_names" layout="@layout/full_month_header" />

     <View
        android:background="@color/calendar_grid_line_inner_vertical_color"
        android:layout_height="1px"
        android:layout_width="match_parent" />

    <com.android.calendar.month.MonthListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:drawSelectorOnTop="false" />

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

直到这里代码工作正常,但有一个空白的白色屏幕和一个操作栏,如果我的问题不明确请尝试编辑它.

What should be done to include Calendar Views (Month, Week, Day) in a custom application ?
Run Code Online (Sandbox Code Playgroud)

android android-source android-xml android-view

8
推荐指数
1
解决办法
1万
查看次数

无法实例化以下类: - com.google.android.gms.plus.PlusOneButton

我正在按照本教程https://developers.google.com/+/mobile/android/recommend在我的应用中集成+1按钮.

一旦我将此代码放入xml中,我就会在GraphicalLayout中出现错误

<com.google.android.gms.plus.PlusOneButton
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
plus:size="standard"
plus:annotation="inline" />
Run Code Online (Sandbox Code Playgroud)

我也试过放入xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"父RelativeLayout,但同样的错误.

The following classes could not be instantiated:
- com.google.android.gms.plus.PlusOneButton (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.


java.lang.NullPointerException
at com.google.android.gms.plus.PlusOneDummyView$zzb.isValid(    at com.google.android.gms.plus.PlusOneDummyView.zzrJ(    at com.google.android.gms.plus.PlusOneDummyView.<init>(    at com.google.android.gms.plus.internal.zzg.zza(    at com.google.android.gms.plus.PlusOneButton.zzN(    at com.google.android.gms.plus.PlusOneButton.<init>(    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(    at sun.reflect.NativeConstructorAccessorImpl.newInstance(    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(    at java.lang.reflect.Constructor.newInstance(    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:438)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:190)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
Run Code Online (Sandbox Code Playgroud)

救命 …

android android-layout android-xml google-plus-one google-play-services

8
推荐指数
1
解决办法
1914
查看次数

在应用XML属性之前恢复视图状态

我有一个自定义视图,让我们说这是它的代码:

public class CustomView extends View {

    boolean visible;
    boolean enabled;

    public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);

        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomView, 0, 0);
        try {
            visible = a.getBoolean(R.styleable.CustomView_visible, true);
            enabled = a.getBoolean(R.styleable.CustomView_enabled, true);
        } finally {
            a.recycle();
        }

        // Apply XML attributes here
    }

    @Override
    public Parcelable onSaveInstanceState() {
        // Save instance state
        Bundle bundle = new Bundle();
        bundle.putParcelable("superState", super.onSaveInstanceState());
        bundle.putBoolean("visible", visible);
        bundle.putBoolean("enabled", enabled);

        return bundle;
    }

    @Override
    public void …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view android-xml android-savedstate

8
推荐指数
1
解决办法
385
查看次数

当键盘宕机时,某些布局不会绘制

我正在使用一个应用程序,SurfaceView在用户定义的某些参数下绘制对象.我为应用程序创建了布局,其中包括页眉,页脚,输入(用户输入要绘制的参数)和自定义SurfaceView.

这是简化的布局:

<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Custom SurfaceView Layout -->

    <org.firengine.myapp.CustomPreview
        android:id="@+id/container_content"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <!-- Header Layout: This is basically a Toolbar, with having a top padding of status bar height (see Note). -->

    <FrameLayout
        android:id="@+id/container_header"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@color/colorTint"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">...</FrameLayout>

    <!-- Footer Layout - This is just a container, with having a bottom padding of navigation bar height (see Note). -->

    <FrameLayout
        android:id="@+id/container_footer"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@color/colorTint" …
Run Code Online (Sandbox Code Playgroud)

java android android-layout android-xml

8
推荐指数
1
解决办法
202
查看次数

Android 之字形布局

我需要在 Android 中创建收据布局。这个想法很简单,一个带有锯齿形顶部的矩形布局。

在此处输入图片说明

甚至,我试过虚线但没有任何效果。

<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="line">

<stroke
   android:color="#FF00"
   android:dashWidth="5dp"
   android:dashGap="5dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml zigzag android-drawable

7
推荐指数
2
解决办法
5414
查看次数