- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在我的 Android Wear 圆形 watch 上出现黑屏(在方形上它可以工作)。
两种布局在 Android Studio 布局设计中都显示正常。
要测试的项目:
https://bitbucket.org/powder366/motoblack
我使用以下代码:
public class MyFragment extends Fragment {
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View contentView = inflater.inflate(R.layout.my_fragment, container, false);
...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
tools:context=".WearFragment">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/text1"
android:text="Hi1"
android:layout_gravity="center_horizontal"
style="@style/UnitsStyle"/>
<TextView
android:id="@+id/text2"
android:text="Hi2"
android:layout_gravity="center_horizontal"
style="@style/BaseStyle"/>
<TextView
android:id="@+id/text3"
android:text="Hi3"
android:layout_gravity="center_horizontal"
style="@style/UnitsStyle"/>
</LinearLayout>
</LinearLayout>
public class MenuAdapter extends FragmentGridPagerAdapter
...
public MenuAdapter(Context context, FragmentManager fm, Handler handler) {
super(fm);
mContext = context;
mHandler = handler;
myFragment = new MyFragment();
}
...
@Override
public Fragment getFragment(int rowNum, int colNum) {
Log.d(TAG, String.format("getFragment(%d, %d)", rowNum, colNum));
if(colNum == 0) {
return myFragment;
}
if(colNum == 1) {
final SecondFragment switchAction = SecondFragment.newInstance(mHandler);
return switchAction;
}
return null;
}
...
public class WearActivity extends Activity {
...
private GridViewPager gridViewPager;
private MenuAdapter menuAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "Create(Wear)");
super.onCreate(savedInstanceState);
setContentView(R.layout.wear_activity);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
menuAdapter = new MenuAdapter(WearActivity.this, getFragmentManager(), mHandler);
gridViewPager = (GridViewPager) findViewById(R.id.pager);
gridViewPager.setAdapter(menuAdapter);
}
});
}
...
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.WatchViewStub
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/watch_view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rectLayout="@layout/rect_activity"
app:roundLayout="@layout/round_activity"
tools:context=".WearActivity"
tools:deviceIds="wear">
</android.support.wearable.view.WatchViewStub>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
tools:deviceIds="wear_square">
<com.xyz.my.ScrollableGridViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"/>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
tools:deviceIds="wear_round">
<com.xyz.my.ScrollableGridViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"/>
</FrameLayout>
public class ScrollableGridViewPager extends GridViewPager {
...
最佳答案
这个问题不是那么小,所以我希望我已经描述得很清楚了。
原因1:
这个问题的真正原因是 onLayoutInflated(WatchViewStub)
方法是两次调用在圆形设备上。
第一次调用 rect_activity.xml
膨胀:
WearActivity$1.onLayoutInflated(WatchViewStub) line: 26
WatchViewStub.inflate() line: 133
WatchViewStub.onMeasure(int, int) line: 141
WatchViewStub(View).measure(int, int) line: 16648
round_activity.xml
完成的。当
onApplyWindowInsets(WindowInsets)
被派出:
WearActivity$1.onLayoutInflated(WatchViewStub) line: 26
WatchViewStub.inflate() line: 133
WatchViewStub.onApplyWindowInsets(WindowInsets) line: 112
WatchViewStub(View).dispatchApplyWindowInsets(WindowInsets) line: 6051
WatchViewStub(ViewGroup).dispatchApplyWindowInsets(WindowInsets) line: 5435
SwipeDismissLayout(ViewGroup).dispatchApplyWindowInsets(WindowInsets) line: 5439
PhoneWindow$DecorView(ViewGroup).dispatchApplyWindowInsets(WindowInsets) line: 5439
ViewRootImpl.dispatchApplyInsets(View) line: 1170
WatchViewStub
组件中)。这种行为在任何地方都没有记录。
MenuAdapter
将被创建(旧的将不再使用,所以谁在乎),而这个新创建的
MenuAdapter
应该在新的
GridViewPager
中设置为适配器.一切都应该“重置”,所以它应该仍然可以正常工作(除了由于布局膨胀两次而不是一次而导致的性能问题)。
GridViewPager
的棘手部分.
GridViewPager
的确切源代码和
FragmentGridPagerAdapter
但它似乎类似于
ViewPager
和
FragmentPagerAdapter
代码。
FragmentPagerAdapter
将新创建的 fragment 添加到
FragmentManager
带特殊
tag
由
id
组成的
ViewPager
和给定子 fragment 的位置:
122 private static String More ...makeFragmentName(int viewId, int index) {
123 return "android:switcher:" + viewId + ":" + index;
124 }
FragmentManager
(在当前
Activity
中)可以通过此
tag
引用将来的名字。
onLayoutInflated(WatchViewStub)
引起的。方法被调用两次。第一个 fragment 是在第一个
MenuAdapter
中创建的并添加到 ID 为
R.id.pager
的容器中(来自
rect_activity.xml
)。然后
round_activity.xml
被夸大了,第二次调用
onLayoutInflated(WatchViewStub)
被调用 - 在新的
MenuAdapter
中创建新 fragment 并添加到新膨胀的
GridViewPager
具有相同 ID:
R.id.pager
.所以第一个 fragment 和第二个 fragment 想要完全相同
tag
在
FragmentManager
.
FragmentPagerAdapter
如果 fragment 具有给定
tag
已存在于
FragmentManager
中它再次附加到它的前一个父级。您可以在此处查看源代码:
50 @Override
51 public Object More ...instantiateItem(View container, int position) {
52 if (mCurTransaction == null) {
53 mCurTransaction = mFragmentManager.beginTransaction();
54 }
55
56 // Do we already have this fragment?
57 String name = makeFragmentName(container.getId(), position);
58 Fragment fragment = mFragmentManager.findFragmentByTag(name);
59 if (fragment != null) {
60 if (DEBUG) Log.v(TAG, "Attaching item #" + position + ": f=" + fragment);
61 mCurTransaction.attach(fragment);
62 } else {
63 fragment = getItem(position);
64 if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
65 mCurTransaction.add(container.getId(), fragment,
66 makeFragmentName(container.getId(), position));
67 }
68 if (fragment != mCurrentPrimaryItem) {
69 fragment.setMenuVisibility(false);
70 }
71
72 return fragment;
73 }
GridViewPager
编号为
R.id.pager
- 但是这个父级不再存在,所以 fragment 不能附加到任何地方(并被显示)。这是实现的东西,只能有一个
ViewPager
- 类似 parent ,在一个
Activity
中具有给定的 ID .
GridViewPagers
设置了不同的 ID。 .一个与
rect_activity.xml
有 ID
R.id.pager1
另一个在
round_activity.xml
有`R.id.pager2'。
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
menuAdapter = new MenuAdapter(WearActivity.this, getFragmentManager());
GridViewPager gridViewPager1 = (GridViewPager) findViewById(R.id.pager1);
if(gridViewPager1!=null) { // rect_activity
gridViewPager1.setAdapter(menuAdapter);
}
GridViewPager gridViewPager2 = (GridViewPager) findViewById(R.id.pager2);
if(gridViewPager2!=null) { // round_activity
gridViewPager2.setAdapter(menuAdapter);
}
}
});
gridViewPager1
找到并且只设置了它的适配器。在第二遍中类似 - 仅适用于
gridViewPager2
的适配器已设置。
GridViewPagers
有不同的 id 在 fragment
tags
中没有冲突,所以最终结果如预期。
WatchViewStub
用于为
rect
提供不同的布局和
round
屏幕。我可以看到您对两种形状使用完全相同的布局。您可以摆脱
WatchViewStub
并这样做:
public class WearActivity extends Activity {
private GridViewPager gridViewPager;
private MenuAdapter menuAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rect_activity);
menuAdapter = new MenuAdapter(WearActivity.this, getFragmentManager());
gridViewPager = (GridViewPager) findViewById(R.id.pager);
gridViewPager.setAdapter(menuAdapter);
}
}
WatchViewStub
的情况下完美运行.
关于android - 圆形 fragment 在模拟器/ watch 中佩戴 watch 变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25808229/
我想知道为什么当我将选定的属性设置为 ON 时,这段代码会给我黑色的 UITableViewCells。如果我这样做,单元格的内容就会完全变黑,我不知道为什么。 这是代码 // // TableVi
我有一个从内容管道加载的 Texture2D。这工作正常,但一旦我尝试在完全不同的 Texture2D 上使用 SetData,我游戏中的所有纹理就会完全变黑: 这是在我的 HUDMeter 类中,我
首先,当我调用 presentViewController:navigationController 时,它会显示正常的绿色导航栏。但是在动画完成后导航栏变得有点暗。 if(!userPageView
我嵌入了一个 UITabBarController 在 UINavigationController 中。 UITabBarController 包含 3 个不同的选项卡,导致 3 个不同的 UIVi
你好,我有tableview,我在其中填充来自网络服务的数据。我首先在表格 View 上显示事件指示器,直到数据来自服务器。问题是,当旋转器移动时, table 会变黑,直到数据出现并且 table
我做了一个简单的自动答题器,但是当我运行它时屏幕变黑,所以我无法停止它等等。我不知道我做错了什么。我想也许我必须集中注意力,但我不确定。代码: import java.awt.AWTException
出于某种原因,如果您突出显示文本区域文本,背景会变成黑色,从而使文本不可读,同样当我选择底部的单选按钮(见附图)时,整个文本区域会再次变黑使文本不可读!有人知道为什么要这样做吗? 这是我的文本区域的代
我在这里看到了这个 SO 问题:Can I tint (black) a UIKeyboard? If so, how? ,其中最佳答案表明您可以进行破解,但这样做可能会使您的应用程序被 Apple
当焦点位于另一个窗口时,我不想让我的主 JFrame 变暗。这是游戏 Football Manager 2012 中的示例。首先选择了主窗口,看起来应该如此,然后在加载时,它变得更暗且无法选择。我不想
我在玩 clone()当我发现一个奇怪的行为时从 jQuery 调用函数。 此代码重现了该问题。第一个 div 包含一个 SVG。两个按钮允许将 SVG 克隆到第二个 div 中。尝试两次会使圆圈变黑
我试图通过创建颜色列表,然后使用 for 循环循环它们,然后重新绘制来在 jframe 中制作闪烁的灯光。但是当我在代码中添加一个 for 循环时,整个事情就出错了,我得到一个黑屏并且它变得不稳定。为
从不同选项卡返回 View Controller 时出现黑屏。 我有以下流程: 带有 5 个选项卡的选项卡栏。 一个名为 Points 的 View Controller ,其中包含一个名为“Rewa
我有一个空 Canvas ,如果我将其渲染为质量为 0.5 的 jpeg,则 jpeg 将是黑色,为什么? 我的代码: var url = canvas.toDataURL('image/jpeg',
我在 iOS 8 中使用 UISearchController,在选项卡 Controller 中嵌入的 View Controller 的 viewDidLoad 中使用以下初始化 _search
当调用 setTextColor 时,TextView 变黑或接近黑色。不知道为什么。任何帮助将不胜感激。 目前正在使用 holo.light。 如下设置我的TextView 当我尝试调用
我正在使用我创建的 UIImageView 的子类,我在其中将其 tintColor 设置为白色: class UIIconView : UIImageView { override init
当我离开带有 ScrollView 的 Activity 然后返回到它时,ScrollView 变黑。发射时,颜色是正确的。就在我离开并返回时,它变黑了。我尝试设置 ScrollView 和内部 Li
我正在制作一个应用程序,它在底部有一堆按钮,在顶部有一堆 ViewStub。所有按钮都指向一个监听器,该监听器在按钮 id 之间切换,以决定扩充哪个 stub 。因此,如果单击按钮 1,则会撤消之前的
使用下面的代码(在 viewDidLoad 中),当我第一次从另一个 View 切换到这个静态相机 View (按下按钮)时,一切正常。然后我派出一个代表,让这个 View 从之前的 View 中消失
我正在使用 Swift 开发我的第一个 iOS 应用程序,我遇到一个问题,当我向我的元素添加约束时,我的一个标签栏 View 在 iOS 模拟器 (iPhone 6) 中变成黑色。我发现我可以有时通过
我是一名优秀的程序员,十分优秀!