我有一个绘制特定图形的任务.作为这项任务的一部分,我需要在45度旋转一些点.
我已经花了2天时间尝试计算一个公式,但却无法做到正确.我一直在寻找这个地方,包括这个特定的网站,我已经非常接近,但我仍然不在那里.
这是:我需要绘制4个不同的点
我有一个特定的公式来计算位置,这超出了问题的范围,但这是我得到的结果:
int radius = 576;
int diameter = radius * 2;
Point blueA = new Point(561, 273);
Point greenB = new Point(273, 561);
Point yellowC = new Point (849, 561);
Point redD = new Point (561, 849);
Run Code Online (Sandbox Code Playgroud)
现在我需要将这个点旋转45度.我使用以下代码来实现它:
double rotationAngle = 45;
double rotationRadians = rotationAngle * (Math.PI / 180);
int center = radius;
result.X = (int)(Math.Cos(rotationRadians) * ((double)result.X - (double)center) - (double)Math.Sin(rotationRadians) * ((double)result.Y - center) + (double)center);
result.Y = (int)(Math.Sin(rotationRadians) * ((double)result.X - (double)center) + …
Run Code Online (Sandbox Code Playgroud) 我有这个问题的textview不在图像按钮下面居中.无论如何要解决这个问题?编码和图像在下面给出!
<LinearLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp">
<RelativeLayout android:gravity="center" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnCat1"
android:src="@drawable/nopic" >
</ImageButton>
<TextView
style="@style/MenuStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="text" />
</RelativeLayout>
<RelativeLayout android:gravity="center" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnContact"
android:src="@drawable/nopic" >
</ImageButton>
<TextView
style="@style/MenuStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true"
android:clickable="false"
android:text="text" />
</RelativeLayout>
</LinearLayout>
<LinearLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp">
<RelativeLayout android:gravity="center" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:onClick="btnRoute"
android:src="@drawable/nopic" >
</ImageButton>
<TextView
style="@style/MenuStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerInParent="true" …
Run Code Online (Sandbox Code Playgroud) 我正在尝试第一次创建一个AsyncTask,但我没有太多运气.
我的AsyncTask需要从服务器获取一些信息,然后将新布局添加到主布局以显示此信息.
一切似乎都或多或少清晰,但错误信息"MainActivity不是一个封闭的类"困扰着我.
没有其他人似乎有这个问题,所以我想我错过了一些非常明显的东西,我只是不知道它是什么.
另外,我不确定我是否使用正确的方法来获取上下文,并且因为我的应用程序没有编译所以我无法测试它.
非常感谢您的帮助.
这是我的代码:
public class BackgroundWorker extends AsyncTask<Context, String, ArrayList<Card>> {
Context ApplicationContext;
@Override
protected ArrayList<Card> doInBackground(Context... contexts) {
this.ApplicationContext = contexts[0];//Is it this right way to get the context?
SomeClass someClass = new SomeClass();
return someClass.getCards();
}
/**
* Updates the GUI before the operation started
*/
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
/**
* Updates the GUI after operation has been completed
*/
protected void onPostExecute(ArrayList<Card> cards) {
super.onPostExecute(cards);
int counter = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试更改FramyLayout的背景颜色.颜色正在改变,但错误的颜色.
但是,如果我通过XML完成它,它工作正常.
这是我的res/values/colors.xml代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="grey">#888888</color>
<color name="white">#FFFFFF</color>
<color name="red">#ffff3448</color>
<color name="green">#ff408c3a</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
以下是我在XML中进行更改时的样子
如果我尝试使用代码,那就是正在发生的事情
FrameLayout frameLayoutBalance = (FrameLayout)view.findViewById(R.id.frameLayoutBalance);
frameLayoutBalance.setBackgroundColor(R.color.green);
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么办了
似乎与android 3.0及更高版本一起正常工作,但是在每次启动应用程序时它都在android 2.3.3上,它再次要求输入用户名/密码.
我正在使用共享首选项.
以下是我保存首选项的方法:
SharedPreferences preferences = MyApplication.getAppContext().getSharedPreferences("athopbalance", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("username", username).commit();
editor.putString("password", password).commit();
Run Code Online (Sandbox Code Playgroud)
以下是我如何阅读它们:
SharedPreferences preferences = MyApplication.getAppContext().getSharedPreferences("athopbalance", Context.MODE_PRIVATE);
String username = preferences.getString("username", "");
String password = preferences.getString("password", "");
Run Code Online (Sandbox Code Playgroud)
我还尝试使用以下代码保存首选项:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MyApplication.getAppContext());
SharedPreferences.Editor editor = preferences.edit();
editor.putString("username", username).commit();
editor.putString("password", password).commit();
Run Code Online (Sandbox Code Playgroud)
并用这段代码读取它们:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MyApplication.getAppContext());
String username = preferences.getString("username", "");
String password = preferences.getString("password", "");
Run Code Online (Sandbox Code Playgroud)
但它也不起作用.
问题是在我重新启动应用程序之前我可以看到它们仍然存在.但是,一旦我重新启动 - 我最终得到用户名""(空字符串)和密码"".
任何想法将不胜感激
我已升级到Android Studio 0.1.6,因此无法编译我的项目.我在代码中遇到了81个错误,这些错误与之前版本的应用程序完美配合.没有代码更改.
所有与R类相关的错误,例如:
java: cannot find symbol
symbol: variable string
location: class %mypackagename%.R
Run Code Online (Sandbox Code Playgroud)
和
java: cannot find symbol
symbol: variable id
location: class %mypackagename%.R
Run Code Online (Sandbox Code Playgroud)
我试图删除"gen"文件夹的内容几次,它重新生成,但它不能解决问题.
我在互联网上寻找解决方案,但找不到任何有类似问题的人.有些人在将项目导入Android Studio时遇到问题,但我的项目是在intellij创意中创建的原创,我一直在使用Android Studio.
顺便说一下,Intellij IDEA还可以编译和运行项目,但我已经习惯了Android Studio.
如果它有任何区别,我正在研究MAC OS 10.8.
非常感谢您的帮助.
更新1:我已经检查过这个帖子,gen和src都被选为源代码,我在代码中的任何地方都没有"import android.r"
上下文
我是开发一个非常大而且非常复杂的项目的开发人员之一.项目的一半用JavaScript编写,另一半用Java编写,而且大约30%的基础产品是预先编译的,所以我们无法完全查看内部或通过它进行调试.
问题
当我们的应用程序返回到前台时,活动堆栈将被销毁,并且仅显示根活动.我无法追查原因.
到目前为止我尝试过的事情
题
是否有任何策略可以找到导致某种生命周期方法被调用的原因?
更新1
感谢您在评论部分提出的重要问题和帮助.这是序列图,以更好地解释发生了什么.
更新2
以下是内存使用情况的屏幕截图
当我启动活动B时
当我将应用程序发送到后台时
当我回到前台
我有一个响应式布局,由一堆元素组成.这是代码的一个非常简化的版本:
HTML:
<div class="parent">
<div class="header"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.parent {
background: red;
display:inline-block;
}
.child {
background: green;
width:100px;
height:100px;
float:left;
}
.header {
background: yellow;
width:100%;
height:30px;
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的是使标题(黄色框)与子div(绿色框)的宽度相同.当首先渲染布局时,它运行良好,这是JSFiddle的截图
但是当屏幕尺寸变得更窄时,标题不会正确缩小,这里是一个较小区域的屏幕截图:
我花了几个小时试图搞清楚,但我做不到.部分挑战是我不知道绿色盒子的数量是什么,因为它们是由.NET动态呈现的
更新1
需要绿色框包装的事实,我想要实现的是黄色框具有与绿色框的组合宽度相同的宽度.期望的结果:
我正在开发一个支持 iOS 14 及更高版本的应用程序,但我想使用一些 SwiftUI 3 属性包装器,例如@FocusState
.
我该如何解决该Stored properties cannot be marked potentially unavailable
错误?
这是我们代码的简化版本,它适用于 Xcode 13,但无法使用 Xcode 14 进行编译。
struct MyView: View {
enum Field: Hashable {
case username
}
@State private var myText: String = ""
@available(iOS 15, *)
@FocusState private var focusedField: Field?
var body: some View {
if #available(iOS 15, *) {
TextEditor(text: $myText)
.focused($focusedField, equals: .username)
} else {
TextEditor(text: $myText)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我无法将计算属性与后备存储解决方法一起使用,因为计算属性不能具有属性包装器。
除了几乎相同的副本之外,我还可以使用其他解决方法吗MyView
?
我有一个复杂的布局,我在这个视图的SwitchLayout上添加了一个标签.
此视图中有一个ImageButton.这是这个按钮的一个小地图:
LinearLayout - > SwitchLayout - > RelativeLayout - > RelativeLayout - > ImageButton
在某些时候,我想将标签附加到SwitchLayout,但我所拥有的只是对ImageButton的引用.
我试图寻找一个ID,但似乎android只是向下搜索,所以
imageButton.findViewById(R.id.switchLayout);
Run Code Online (Sandbox Code Playgroud)
不起作用.
看起来我也无法直接从ImageButton获取指定的标签.
这段代码:
imageButton.getTag()
Run Code Online (Sandbox Code Playgroud)
回报 null
我找到的唯一一个解决方法是在这里,但它很难看:
ViewSwitcher viewSwitcher = (ViewSwitcher)imageButton.getParent().getParent().getParent();
viewSwitcher.getTag();
Run Code Online (Sandbox Code Playgroud)
我想尽可能一周地进行耦合,所以我想知道是否有一种方法可以将标签分配给viewSwitcher及其所有的子节点,
或者在父视图中查找ViewById.