这是我的问题.我有一个花栗鼠的刚体(苏打水可以站立起来),我想将它的重心改变到物体的底部,这样当它的上部施加一个力时它就会落在它的侧翼上.
我是在正确的轨道上吗?
1)由于某种原因,我无法将身体的重心设置为特定值.有人有一个简单的解决方案吗?
2)精灵的重心怎么样?我是否还需要更改它?如果是这样,怎么样?
谢谢你澄清一下.
约翰·T
对于使用重力而不是layout_gravity或者没有使父视图足够宽的所有人都很抱歉.我没有犯这些错误,但是textView1一直被推到行的左边,而textView2正在向右推.据我所知,testView2应该固定在行的右侧,这实际上是整个屏幕的右侧.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/hwTable"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HW Part"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Make / Model"
android:layout_gravity="right"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
<Button
android:id="@+id/vitalsDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Back" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我已经尝试了许多不同的技术,在我的游戏中应用逼真的重力特征但到目前为止没有运气.我计划为那些可以向我展示或(分享)一些将重力应用于Cocos2D中的CCSprite的代码的人提供100点奖励.
到目前为止,我所做的只是丑陋或不切实际,我已经在很多不同的地方询问最好的方法是什么,但我还没有找到任何好看的重力技术.
无论如何,任何人都可以提供一些技巧/想法或他们的方法,只在不使用物理引擎的情况下将重力应用于Cocos2D中的CCSprite ?
谢谢!
我想在视图底部有一个不同小部件的“工具栏” ...每个小部件都由ImageView代表图标和TextView描述的组成。这是XML代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linear_layout_shelves"
android:background="@drawable/final_shelves"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginLeft="70dp"
android:layout_marginRight="65dp"
android:layout_marginTop="@dimen/first_shelf_margin_top"
android:orientation="horizontal" >
<ImageView
android:id="@+id/image_11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:src="@drawable/image1"
android:clickable="true"/>
<ImageView
android:id="@+id/image_12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:src="@drawable/image2"
android:clickable="true" />
<ImageView
android:id="@+id/image_13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:src="@drawable/image3"
android:clickable="true" />
</LinearLayout>
<!-- "Tools" : Cancel, delete, details -->
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
>
<!-- Cancel Widget -->
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/delete_widget"
android:layout_weight="1"
android:visibility="visible">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cancel_icon"
android:src="@drawable/cancel_128"
android:clickable="true" …Run Code Online (Sandbox Code Playgroud) 我的客户想要使用Gravity Forms来创建表单 - 他让部门经理访问WordPress仪表板,然后每个经理都会进入并创建表单.没问题.
但是,客户端为WordPress外部的最终用户(成员)提供了一个特殊的界面.他希望使用Gravity Forms创建的表单显示在此界面中.我可以创建短代码或使用函数'gravity_form()'来调用表单,但随后它们总是与WordPress标题/布局/等一起显示.
有没有办法可以访问并显示表格?(我尝试在创建表单时单击"预览"选项时显示预览的方式类似.但是,我得到'这是预览'消息).
我正在 Unity 3d 中制作一个应用程序,我想自己编写重力和向心力的代码,但我得到了奇怪的结果,我这样做对吗?这是我的代码:
public void Attract(MassObject[] _allMass)
{
Vector3 F = new Vector3();
Vector3 C = new Vector3();
foreach(MassObject i in _allMass)
{
// gravity pull
F.x = GV.gravity * ((mass * i.mass) / (obj.position.x - i.obj.position.x));
F.y = GV.gravity * ((mass * i.mass) / (obj.position.y - i.obj.position.y));
F.z = GV.gravity * ((mass * i.mass) / (obj.position.z - i.obj.position.z));
// centripital force
C.x = (mass * Mathf.Pow(vel.x,2)) / (obj.position.x - i.obj.position.x);
C.y = (mass * Mathf.Pow(vel.y,2)) / (obj.position.y - …Run Code Online (Sandbox Code Playgroud) 由于某种原因,我的 FAB 不会像往常一样进入屏幕的右下角。我在一个片段中,该片段是一个协调器布局(我不知道这是否是一个好习惯)。
这是布局xml代码:
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gigstudios.polls.fragment.MyPollsFragment">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add_white_36dp"
app:fabSize="normal"
app:layout_anchor="@id/linear_layout"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
出于某种原因,FAB 最终位于右上角而不是右下角。有谁知道我做错了什么?
顺便说一句,xml 预览总是在右下角显示 fab 按钮,但是当我在手机上运行它时,它在右上角。
编辑:这是我的 main_activity xml,用于显示我放置片段的位置(“容器”FrameLayout)。
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGrey">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGrey"
android:layout_marginTop="?attr/actionBarSize">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container">
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android gravity floating-action-button android-coordinatorlayout
我正在尝试创建一个简单的弹力球模拟器,我希望球以与现实生活中大致相同的速度移动.然而,目前,在从5英尺处跌落后,球几乎立即撞到地面并反弹几次然后停在一秒之内.我知道我可以尝试我的重力值直到它是半现实的,但我很困惑为什么我当前的重力值不起作用.这是我如何获得当前的一个:
现实生活中的重力= 9.8米/秒^ 2
= 32.152英尺/秒^ 2
= 1/72英尺/ 1/30秒^ 2(我的程序中我的帧率设置为30)
=每1/30秒^ 102.887像素^ 2(我的程序中一英尺是96像素)
这是我移动球的代码(使用Processing 3.2.1):
void move() {
dy+=102.88704; //gravity
x+=dx;
y+=dy;
z+=dz;
if(y+size*8>480) {
dy*=-0.85;
}
y=constrain(y,-100000.0,480-(size*8));
}
Run Code Online (Sandbox Code Playgroud)
目前,x和z只保持在0.因为它从5英尺处掉落,当它达到480尺寸*8(尺寸以英寸为单位)时它会撞到地面.0.85的值是暂时的,我可能稍后调整它,但它不应该对这个问题产生任何影响.非常感谢任何和所有的帮助.谢谢!
我想像彗星一样制作动画文字.我想创建一个重力效果,加速矢量上的影片剪辑,在舞台上设置一个起始位置并从xml文件加载文本.
我有一个关于box2d和cocos2d的问题.我的世界没有引力,我在瓦片基础游戏中工作.我正在使用潜行操纵杆来移动精灵并且它的移动完美但是当我释放指向操纵杆时,我的精灵身体因为一些力量而无法停止.我想在操纵杆释放时停止精灵的移动.
-(void)update:(ccTime)dt :(b2Body *)ballBody :(CCSprite *)player
{
CGPoint scaledVelocity=ccpMult(joysticks.velocity, 2);
NSLog(@"Joystick Velocity X: %f",joysticks.velocity.x);
NSLog(@"Joystick Velocity Y: %f",joysticks.velocity.y);
b2Vec2 force=b2Vec2(scaledVelocity.x/PTM_RATIO,scaledVelocity.y/PTM_RATIO);
ballBody->ApplyLinearImpulse(force, ballBody->GetWorldCenter());
}
Run Code Online (Sandbox Code Playgroud)
这里scaledVelocity值是近似0到1.当我释放操纵杆时,操纵杆的时间值是0.0
请帮助我,因为过去5天我被卡住了.请帮我.
提前致谢
如何在水平LinearLayout中制作4个固定大小的按钮水平填充该图层的空间,让Android在这些按钮之间填充所需空间以填充该空间?
android autofill gravity android-layout android-linearlayout
我是android编程的新手。
我只是发现xml不是设置布局的唯一方法。因此,我试图了解以编程方式设置的布局。我一直在尝试更改按钮的位置。我如何设置布局重力,以便将按钮定位在预期的轴上,比方说 bottom和center?
顺便说一句,是icicle同样的事情savedInstanceState?
这是我偶然发现的编码。您能告诉我设置重力的正确方法吗?
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout one = new LinearLayout(this);
myButton1 = new Button1(this);
one.addView(myButton1,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0));
myButton2 = new Button2(this);
one.addView(mButton2,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0));
setContentView(one);
Run Code Online (Sandbox Code Playgroud) gravity ×12
android ×4
android-xml ×1
autofill ×1
box2d-iphone ×1
c# ×1
chipmunk ×1
dynamic ×1
ios ×1
iphone ×1
layoutparams ×1
math ×1
movieclip ×1
php ×1
processing ×1
text ×1
wordpress ×1
xml ×1