小编dmn*_*nlk的帖子

我何时应该在片段中获得宽度视图

我在Linearlayout.LinearLayout中以编程方式添加了View(按钮),在Fragment中由XML进行了布局.

我想获得按钮宽度,但总是返回0.

我用Google搜索了这个问题,

getWidth仅适用于WindowsFocusChanged.

 public void onWindowFocusChanged(boolean hasFocus) { }
Run Code Online (Sandbox Code Playgroud)

但片段没有这种方法.

如何在Fragment中获取View宽度?

android android-layout android-fragments

9
推荐指数
2
解决办法
6209
查看次数

如何在intel x86仿真器上使用GCM

我正在使用x86英特尔Android模拟器开发Android应用程序.

但是当我使用google croud messaging API时,出现错误.

java.lang.UnsupportedOperationException: Device does not have package com.google.android.gsf

如果使用谷歌API的开关模拟器,错误很明显.但很慢....

我搜索过相同的情况,我找到了Google Maps API.

如何使用谷歌api为英特尔x86原子图像创建avd?

http://38911bytes.blogspot.de/2012/03/how-to-use-google-maps-api-in-android.html

但这些文章只是Google Maps问题,不适用于GCM API.

有解决方案吗?

android android-emulator

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

如何通过子视图知道 LinearLayout 的索引?

我的布局是这样的

<ParentLinearlayout>
    <ChildLinearlayout>
       <Button>
    </ChildLinearlayout>
    <ChildLinearlayout>
       <Button>
    </ChildLinearlayout>
</ParentLinearlayout1>
Run Code Online (Sandbox Code Playgroud)

ChildLinearlayout 的数量改变,动态添加和删除。

单击按钮时,我想删除作为 Button 父级的 ChildLinearlayout。

但我不知道索引线性布局。索引经常更改,因此不能使用标签。

如何知道 LinearLayout 索引?

android android-layout

3
推荐指数
1
解决办法
3143
查看次数

Textview布局中心在ScrollView中以编程方式垂直和水平

应用程序具有scrollviewXML布局.

<ScrollView
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
       >
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

我想textView进入这个scrollView中心.

我试过这个代码,设置水平中心,但垂直顶部..我想两个居中.

LinearLayout l1 = new LinearLayout(getActivity());
            l1.setOrientation(LinearLayout.VERTICAL);
            l1.setGravity(Gravity.CENTER);
            l1.setBackgroundColor(Color.WHITE);
            TextView errorView = new TextView(getActivity());
            LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
                    new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            errorView.setText("TextView");
            errorView.setTextColor(Color.BLACK);
            errorView.setLayoutParams(params);
            errorView.setGravity(Gravity.CENTER);
            l1.addView(errorView);
            scrollViewCon.addView(l1, lparams);
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

android android-layout

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

如何在getView方法中通过Button OnClick控制textview

我的应用程序有Listview,Listview项目有一个TextView和一个Button和其他图像等...我使用ViewHolder模式.

单击按钮时,我想在TextView中更改文本

如何在按钮Onclick中控制TextView?

 public class AListAdapter extends ArrayAdapter<MyData> {

    static class ViewHolder {

        TextView viewCountView;

        ImageButton myButton;

        ImageView profileImageView;

    }

    public View getView(int position, View convertView, ViewGroup parent) {
        final AListAdapter adapter = this;
        ViewHolder holder = null;


        if (convertView == null) {
            convertView = inflater.inflate(R.layout.cell parent, false);
            TextView viewCountView = (TextView) convertView.findViewById(R.id._view_count_);
            Button likeButton = (ImageButton) convertView.findViewById(R.id._like_button);
            LoadImageView profileImageView = (LoadImageView) convertView.findViewById(R.id.albumlist_profile_image);

            holder = new ViewHolder();
            holder.viewCountView = viewCountView;
            holder.likeButton = likeButton;
            holder.profileImageView = profileImageView;

            holder.likeButton.setOnClickListener(new View.OnClickListener() {
                @Override …
Run Code Online (Sandbox Code Playgroud)

android

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

无法从方法中获取@override 注释

当我从class实例中获取方法并想要获取@override注释时。但是方法没有任何注释。获得@override 注解是不可能的吗?

代码如下。

package com.test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import javax.annotation.Resource;

public class ReflectionTest {

    public static void main(String[] args) throws Exception {
        ChildHoge childHoge = new ChildHoge();
        Method method = childHoge.getClass().getMethod("init");
        for (Annotation s : method.getAnnotations()) {
            System.out.println(s);
        }
        Method method2 = childHoge.getClass().getMethod("a");
        for (Annotation a : method2.getAnnotations()) {
            System.out.println(a); // =>@javax.annotation.Resource(mappedName=, shareable=true, type=class java.lang.Object, authenticationType=CONTAINER, lookup=, description=, name=)

        }
    }

}

class SuperHoge {
    public void init() {

    }
}


class ChildHoge extends …
Run Code Online (Sandbox Code Playgroud)

java annotations

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