我在Linearlayout.LinearLayout中以编程方式添加了View(按钮),在Fragment中由XML进行了布局.
我想获得按钮宽度,但总是返回0.
我用Google搜索了这个问题,
getWidth仅适用于WindowsFocusChanged.
public void onWindowFocusChanged(boolean hasFocus) { }
Run Code Online (Sandbox Code Playgroud)
但片段没有这种方法.
如何在Fragment中获取View宽度?
我正在使用x86英特尔Android模拟器开发Android应用程序.
但是当我使用google croud messaging API时,出现错误.
java.lang.UnsupportedOperationException: Device does not have package com.google.android.gsf
如果使用谷歌API的开关模拟器,错误很明显.但很慢....
我搜索过相同的情况,我找到了Google Maps API.
http://38911bytes.blogspot.de/2012/03/how-to-use-google-maps-api-in-android.html
但这些文章只是Google Maps问题,不适用于GCM API.
有解决方案吗?
我的布局是这样的
<ParentLinearlayout>
<ChildLinearlayout>
<Button>
</ChildLinearlayout>
<ChildLinearlayout>
<Button>
</ChildLinearlayout>
</ParentLinearlayout1>
Run Code Online (Sandbox Code Playgroud)
ChildLinearlayout 的数量改变,动态添加和删除。
单击按钮时,我想删除作为 Button 父级的 ChildLinearlayout。
但我不知道索引线性布局。索引经常更改,因此不能使用标签。
如何知道 LinearLayout 索引?
应用程序具有scrollview
XML布局.
<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)
为什么会这样?
我的应用程序有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) 当我从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)