我找不到一个如何做到这一点的好例子.
我有一个设置x高度的RelativeLayout.
我想添加一个按钮,将高度扩展到x + y高度.
有人可以通过编程方式向我介绍一个很好的例子吗?
我想在Activity中调整一些布局的大小.
这是主XML的代码:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/top"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#3ee3e3" >
</LinearLayout>
<LinearLayout
android:id="@+id/middle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:id="@+id/bottom"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#fe51e6" >
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如您所见,顶部和底部布局高度为0,中间布局覆盖所有位置.
我想以编程方式减少中间布局大小,同时增加顶部和底部布局大小,直到所有布局具有相同的高度.
我希望它看起来像一个动画.
我该怎么办?
谢谢
我正在尝试确定一些UI元素的实际像素尺寸!
这些元素从.xml文件中膨胀,并使用dip宽度和高度进行初始化,以便GUI最终支持多个屏幕大小和dpi(如android规范所推荐).
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="150dip"
android:orientation="vertical">
<ImageView
android:id="@+id/TlFrame"
android:layout_width="110dip"
android:layout_height="90dip"
android:src="@drawable/timeline_nodrawing"
android:layout_margin="0dip"
android:padding="0dip"/></LinearLayout>
Run Code Online (Sandbox Code Playgroud)
此前的xml表示一帧.但是我在这里描述的水平布局中动态添加了许多:
<HorizontalScrollView
android:id="@+id/TlScroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_margin="0dip"
android:padding="0dip"
android:scrollbars="none"
android:fillViewport="false"
android:scrollbarFadeDuration="0"
android:scrollbarDefaultDelayBeforeFade="0"
android:fadingEdgeLength="0dip"
android:scaleType="centerInside">
<!-- HorizontalScrollView can only host one direct child -->
<LinearLayout
android:id="@+id/TimelineContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_margin="0dip"
android:padding="0dip"
android:scaleType="centerInside"/>
</HorizontalScrollView >
Run Code Online (Sandbox Code Playgroud)
定义为在我的java代码中添加一个框架的方法:
private void addNewFrame()
{
LayoutInflater inflater = (LayoutInflater) _parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.tl_frame, null);
TextView frameNumber = (TextView) root.findViewById(R.id.FrameNumber);
Integer val = new Integer(_nFramesDisplayed+1); //+1 …Run Code Online (Sandbox Code Playgroud) android android-widget android-ui android-layout android-xml
我指的是这里的扩展/折叠动画代码.
虽然它有效,但它不能很好地完成工作.动画不流畅.
我做了一些登录代码.
public static void expand(final View v) {
v.measure(MeasureSpec.makeMeasureSpec(((View)v.getParent()).getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(1024, MeasureSpec.AT_MOST));
final int targtetHeight = v.getMeasuredHeight();
v.getLayoutParams().height = 0;
v.setVisibility(View.VISIBLE);
Animation a = new Animation()
{
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1
? LayoutParams.WRAP_CONTENT
: (int)(targtetHeight * interpolatedTime);
Log.i("CHEOK", "E v.getLayoutParams().height = " + v.getLayoutParams().height);
v.requestLayout();
}
Run Code Online (Sandbox Code Playgroud)
将打印以下日志消息.
10-09 12:29:58.808: I/CHEOK(7874): E v.getLayoutParams().height = 0
10-09 12:29:58.808: I/CHEOK(7874): E v.getLayoutParams().height = 0
10-09 12:29:58.918: I/CHEOK(7874): E v.getLayoutParams().height = 11 …Run Code Online (Sandbox Code Playgroud) 我有一个包含卡片列表的RecyclerView,每个卡片都扩展为子卡片.
每张卡片都有不同的文字.我希望当用户点击子卡时,它会展开以显示内部文本.扩展高度取决于卡包含的文本量.
我尝试使用以下方法测量目标高度:
view.Measure(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
Run Code Online (Sandbox Code Playgroud)
然后将卡扩展到Measured Height(参见此处).但是,它为所有卡提供相同的测量高度.
这是主适配器,它创建并绑定父卡和子卡:
public class HalachaExpandableAdapter : ExpandableRecyclerAdapter<HalachaParentViewHolder, HalachaChildViewHolder>, View.IOnClickListener
{
LayoutInflater _inflater;
bool expand;
int targetHeight;
bool wave = false;
public HalachaExpandableAdapter(Context context, List<IParentObject> itemList) : base(context, itemList)
{
_inflater = LayoutInflater.From(context);
}
public override void OnBindChildViewHolder(HalachaChildViewHolder childViewHolder, int position, object childObject)
{
var halachaChild = (HalachaChild)childObject;
childViewHolder.halachaChildTitle.Text = halachaChild.Title.ToString();
targetHeight = childViewHolder.halachaChildCard.Height;
childViewHolder.halachaChildCard.LayoutParameters.Height = 100;
childViewHolder.halachaChildCard.SetOnClickListener(this);
expand = childViewHolder.expand;
}
public override void OnBindParentViewHolder(HalachaParentViewHolder parentViewHolder, int …Run Code Online (Sandbox Code Playgroud) 在android中如何使用动画从一个点增长图像?
我的意思是说......我有一个按钮..我想要的是当我点击那个按钮时我的图像必须增长(升序)从那一点变得越来越大......然后我又一次点击那个再次按钮它必须折叠越来越小,以此结束
任何人都可以帮助我使用Android动画吗?我是android的新手
我有一个带有项目的ListView.当用户单击某个项目时,它的高度应该缩放为零,并且下面的所有项目都应向上滚动.我下面的代码不起作用.使用我的代码,点击的项目向右缩放,但下面的项目不向上滚动,它们保持在相同的位置.我也尝试过使用LinearLayout但是存在同样的问题.
有一个应用程序可以做到这一点.它叫做任务.

我目前的实现如下:
@Override
public void onItemClick(AdapterView<?> arg0, View v, final int index,
long id) {
Animation anim = AnimationUtils.loadAnimation(getActivity(),
R.anim.scaleup);
v.startAnimation(anim);
}
Run Code Online (Sandbox Code Playgroud)
<set android:shareInterpolator="false" >
<scale
android:duration="700"
android:fillAfter="false"
android:fillBefore="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotY="0%"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
Run Code Online (Sandbox Code Playgroud)
我有一个recyclerView,它包含一个自定义视图列表.当我单击recyclerView项时,它会被展开,提供更多信息.另一次点击此视图(或另一个视图)将关闭当前视图.提供的默认动画SimpleItemAnimator似乎不合适.所以,我试着animateChange像我一样自己实现:
public class CustomItemAnimator extends CustomDefaultItemAnimator {
private static final int FADE_IN = 1;
private static final int FADE_OUT = 2;
private ItemHolderInfo getItemHolderInfo(RecyclerView.ViewHolder viewHolder, MoveInfo moveInfo) {
moveInfo.stuff.clear();
ViewGroup content_container = (ViewGroup) viewHolder.itemView.findViewById(R.id.item_content);
for (int i = 0; i < content_container.getChildCount(); i++) {
View view = content_container.getChildAt(i);
if (view.getVisibility() == View.VISIBLE) {
moveInfo.stuff.put(view.getId(), new Pair<>(view.getTop(), view.getBottom()));
}
}
moveInfo.stuff.put(viewHolder.itemView.getId(), new Pair<>(viewHolder.itemView.getTop(), viewHolder.itemView.getBottom()));
moveInfo.stuff.put(content_container.getId(), new Pair<>(content_container.getTop(), content_container.getBottom()));
return moveInfo;
}
@NonNull
@Override
public ItemHolderInfo recordPreLayoutInformation(@NonNull RecyclerView.State …Run Code Online (Sandbox Code Playgroud) android android-animation android-scrollview android-recyclerview
我动态地将图像视图添加到我的线性布局中,
我想实现
以下是我所做的示例代码
主要活动
package ksp.com.animationssample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
private Button btn_expand;
private Button btn_collapse;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_expand = (Button) findViewById(R.id.btn_expand);
btn_collapse = (Button) findViewById(R.id.btn_collapse);
LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
final LinearLayout layout = (LinearLayout) findViewById(R.id.imageLayout);
for (int i = 0; i < 3; i++) {
final ImageView image = new ImageView(MainActivity.this); …Run Code Online (Sandbox Code Playgroud) 我设法做了我的cardViewAdapter,但我阻止扩大我的卡.我恢复了这个响应的代码(这里的类名是CardsAnimationHelper:)来做动画,但它是叠加的.
我解决了上面的问题,但如果在我的cardView上我同时显示10个元素的50个列表.如果我扩展第一个,数字11,21,31,41也将扩展.你有诀窍吗?
我反思过,这对我来说毫无意义.就在我的OnClick方法之前,我显示了一个textview,其中文本是位置.但是当我点击id是正确的,这意味着当我点击它时会检测到几张牌上的点击.我想我的OnClickListener中的视图可能有问题
我的CardView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="2dp"
app:cardElevation="2dp">
<!-- Les CardView possèdent des attributs supplémentaires dont
- cardBackgroundColor
- cardElevation pour l'élévation (donc aussi l'ombre)
- cardCornerRadius pour arrondir les angles
-->
<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">
<!-- Les CardView agissent comme des FrameLayout,
pour avoir une organisation verticale nous devons
donc rajouter un LinearLayout -->
<TextView
android:id="@+id/text_cards" …Run Code Online (Sandbox Code Playgroud) android ×10
animation ×5
layout ×2
android-ui ×1
android-xml ×1
java ×1
listview ×1
xamarin ×1