小编sac*_*n10的帖子

如何在布局xml文件中使用时指定id

在我的布局xml文件中,我已经包含了其他布局xml文件(每个文件都有不同的android id).

<include layout="@layout/view_contact_name" android:id="+id/test1"/>
<include layout="@layout/view_contact_name" android:id="+id/test2"/>
Run Code Online (Sandbox Code Playgroud)

但是,当我在模拟器中运行它,并开始层次查看器,每个布局仍显示"NO_ID",并在我的代码,我 findViewById(R.id.test1)findViewById(R.id.test2)两个返回null.

有人可以帮我解决我的问题吗?

android android-layout

111
推荐指数
4
解决办法
7万
查看次数

图像视图不包装内容

我有一个ImageView包装这个图像:

<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:scaleType="fitStart"
    android:src="@drawable/oncmap"/>
Run Code Online (Sandbox Code Playgroud)

一个TextView,就在它下面.不幸的是,它根据设备的屏幕尺寸将其推向视图或视图外.

http://i.imgur.com/CuVFK5P.png

http://i.imgur.com/6wzMebV.jpg

我可以"破解"它,但它不是......

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="16dp"
android:orientation="vertical"
tools:context="MapFragment">

<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/oncmap"/>

<TextView
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:text="Neptune"
    style="@style/sectionHeader"/>

<TextView
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="16dp"
    android:text="@string/info"
    style="@style/text"/>
Run Code Online (Sandbox Code Playgroud)

java android imageview

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

如何在android中禁用卡片视图周围的阴影

您好我正在使用演示应用程序,我正在使用支持库的卡片视图.默认情况下,它会在它周围添加阴影.我想删除这个阴影,看起来应该很简单.

我试过这个对我不起作用.

CardView cardView = (CardView) v.findViewById(R.id.cardView);
cardView.setElevation(0);
Run Code Online (Sandbox Code Playgroud)

做完这些之后我就崩溃了

11-06 15:12:17.018: E/AndroidRuntime(24315): FATAL EXCEPTION: main
11-06 15:12:17.018: E/AndroidRuntime(24315): Process: com.xyz, PID: 24315
11-06 15:12:17.018: E/AndroidRuntime(24315): java.lang.NoSuchMethodError: android.support.v7.widget.CardView.setElevation
11-06 15:12:17.018: E/AndroidRuntime(24315):    at com.xyz.adapters.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:85)
11-06 15:12:17.018: E/AndroidRuntime(24315):    at com.xyz.adapters.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:1)
11-06 15:12:17.018: E/AndroidRuntime(24315):    at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:2915)
11-06 15:12:17.018: E/AndroidRuntime(24315):    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:2511)
11-06 15:12:17.018: E/AndroidRuntime(24315):    at android.support.v7.widget.LinearLayoutManager$RenderState.next(LinearLayoutManager.java:1425)
11-06 15:12:17.018: E/AndroidRuntime(24315):    at android.support.v7.widget.LinearLayoutManager$RenderState.next(LinearLayoutManager.java:1425)
Run Code Online (Sandbox Code Playgroud)

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res/com.xyz"
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:orientation="horizontal" >
Run Code Online (Sandbox Code Playgroud)

提前致谢.

android android-cardview

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

有多少种方法可以将位图转换为字符串,反之亦然?

在我的应用程序中,我想以字符串的形式将位图图像发送到服务器,我想知道有多少种方法可以将位图转换为字符串.现在我使用Base64格式进行编码和解码,它需要更多的内存.有没有其他可能以不同的方式做同样的事情,这需要更少的内存消耗.现在我正在使用此代码.

Resources r = ShowFullImage.this.getResources();
Bitmap bm = BitmapFactory.decodeResource(r, R.drawable.col);
ByteArrayOutputStream baos = new ByteArrayOutputStream();  
bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object   
byte[] b = baos.toByteArray();

String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
Run Code Online (Sandbox Code Playgroud)

java android bitmapdata

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

在Android中获取布局inflater的正确方法是什么?

有一种方法可以获得layoutInflater:

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

另一种方式是:

LayoutInflater inflater = LayoutInflater.from(context);
Run Code Online (Sandbox Code Playgroud)

第三个(当我参加活动时)是:

LayoutInflater inflater = getLayoutInflater();
Run Code Online (Sandbox Code Playgroud)

那么他们之间有什么区别?

请注意,当我将第三个inflater发送到我的适配器时,我的应用程序工作.但是当我发送上下文并通过第二种方式创建了inflater时,它没有!

java android layout-inflater

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

从assets文件夹加载图像

我有一个Android应用程序,其中我有资产文件夹中的几个图像.现在我想制作一组图像.现在我的问题是: - 当我们的图像处于可绘制状态时,我们可以制作一个类似的数组

int x[] = {
    R.drawable.ss,
    R.drawable.aa, R.drawable.sk,
    R.drawable.xx
};
Run Code Online (Sandbox Code Playgroud)

等等.当我的图像在资源文件夹中时,如何制作与上面相同的图像数组.我想在类级别创建一个数组.

java android

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

使用moq验证对具有param参数的函数的调用

我有一个带LogTrace的ILogger接口(字符串值,params object []参数).现在我想验证是否调用了LogTrace并且要记录的字符串包含一些id.问题是它可以被不同地调用.例如1)LogTrace("MyString"+ id)2)LogTrace("MyString {0}",id)等等.

有没有一种方法可以让Moq验证所有场景?我只能想到创建一个手工制作的模拟器,它将格式化可用于验证的字符串.

c# moq function

13
推荐指数
1
解决办法
6635
查看次数

Android通过.net webservices发送推送通知

我正在使用以下webservice从Android发送推送通知.当我第一次调用此Web服务时,需要花费很多时间并且Android设备上不会发送推送通知.它只在从Android调用时才会发生.它完美地作为webservice.

[WebMethod]

    public string SendGcm(String serviceKey,String registrationId ,string message) {
        WebClient wc=new WebClient();
        wc.Headers.Add("Authorization", "key=" + serviceKey);
        NameValueCollection nameValues=new NameValueCollection
            {
                {"registration_id", registrationId},
                {"collapse_key", Guid.NewGuid().ToString()},
                {"data.payload", message}
            };

        var resp=wc.UploadValues("https://android.googleapis.com/gcm/send",
                    nameValues);

        var respMessage = Encoding.Default.GetString(resp);
                return respMessage;
    }
Run Code Online (Sandbox Code Playgroud)

java web-services android-ksoap2 google-cloud-messaging android-webservice

12
推荐指数
1
解决办法
1196
查看次数

如何将监听器附加到单选按钮

我有一个显示各种radiobutton的活动.无线电按钮分组在无线电组中.我希望在检查某个单选按钮时,一些radiobutton会消失.例如,当检查事故按钮时,摔倒,绊倒和疾病的无线电按钮消失.我怎么能实现这个目标?

我有愚蠢的代码,但需要以某种方式将监听器附加到事件按钮.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.reportsomethinglayout);

         resolution = (EditText)findViewById(R.id.editTextresolution);
        // resolution.setInputType(InputType.TYPE_NULL);
        // showSoftKeyboard(resolution);



         accident  = (RadioButton)findViewById(R.id.radioButtonaccident);
         incident  = (RadioButton)findViewById(R.id.radioButtonincident);
         concern  = (RadioButton)findViewById(R.id.radioButtonconcern);
         fall  = (RadioButton)findViewById(R.id.radioButtonfall);
         trip  = (RadioButton)findViewById(R.id.radioButtonTrip);
         illness  = (RadioButton)findViewById(R.id.radioButtonillness);





    }



     public void onRadioButtonClicked(View view) {
            // Is the button now checked?
            boolean checked = ((RadioButton) view).isChecked();

            // Check which radio button was clicked
            switch(view.getId()) {
                case R.id.radioButtonaccident:
                    if (checked)
                        Log.e(TAG, "accident radiobutton checked");
                    break;
                case R.id.radioButtonincident:
                    if (checked)
                        Log.e(TAG, "incident radiobutton checked");

                            fall.setVisibility(View.GONE);
                            trip.setVisibility(View.GONE); …
Run Code Online (Sandbox Code Playgroud)

java android radio-button

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

用边框Android表示进度

我需要以边界来表示进步.例如,最初视图根本没有任何边框,当达到50%的进度时,只有50%的视图将获得边框.找到附加的图像.我做了很多谷歌搜索,但没有运气.我使用的视图是textview.

在此输入图像描述

编辑

以下代码切割位图的边缘.我在这段代码中所做的是 - 1. Bg设置为Black Hexagon 2.我采用了空心的绿色边框六边形并露出这个空心六边形,这样看起来边框会越来越累积.

public class MyView extends View {

private Bitmap mBitmap;
private Paint mPaint;
private RectF mOval;
private float mAngle = 135;
private Paint mTextPaint;
private Bitmap bgBitmap;

public MyView(Context context) {
    super(context);
    doInit();
}


/**
 * @param context
 * @param attrs
 * @param defStyleAttr
 */
public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // TODO Auto-generated constructor stub
    doInit();
}


/**
 * @param context
 * @param attrs
 */
public MyView(Context …
Run Code Online (Sandbox Code Playgroud)

java android android-custom-view android-progressbar progress-bar

6
推荐指数
1
解决办法
697
查看次数