एक अजीब मिला है, तो LinearyLayout का आकार बदल नहीं जाएगा। मैंने इसे एक बहुत ही सरल उदाहरण में लाने में कामयाब रहा है। वास्तव में इसे समझ नहीं सकता है।इसकी ऊंचाई एक बार 0
मुझे लाइनरलाउट के अंदर एक लीनियरआउट मिला है। मैं एनीमेशन का उपयोग करके बच्चे का आकार बदलना चाहता हूं (जिसे मैं कभी-कभी इलाज कर रहा हूं)। मेरा लेआउट एक्सएमएल यहाँ है।
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
<!-- Lots more controls will appear above -->
<LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/animation_subject">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:gravity="center" />
</LinearLayout>
<!-- Lots more controls will appear below -->
</LinearLayout>
<Button android:text="Slide it Down!" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="btnDoAnimDown_OnClick" />
</LinearLayout>
अब, जैसा कि आप देख सकते हैं, एक बटन है, और यहां उस बटन का कोड है।
public void btnDoAnimDown_OnClick(View v)
{
View pnlSlider = findViewById(R.id.animation_subject);
pnlSlider.measure(1000, 1000);
DropDownAnim anim = new DropDownAnim(pnlSlider, pnlSlider.getMeasuredHeight(), true);
anim.setDuration(2000);
pnlSlider.startAnimation(anim);
return;
}
यदि आप इसे अभी चलाने के लिए थे, तो यह नीचे नहीं गिर जाएगा। बिलकुल। हालांकि, अगर आप बटन को लाइनरलायआउट में ले जाना चाहते थे, जिसे मैंने अवलोकन नाम दिया है और इसे चाइल्ड लीनियरलाउट के बाद रखा है, तो यह एक इलाज करता है! इस तरह ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
<!-- Lots more controls will appear above -->
<LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:id="@+id/animation_subject">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:gravity="center" />
</LinearLayout>
<!-- Lots more controls will appear below -->
<Button android:text="Slide it Down!" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="btnDoAnimDown_OnClick" />
</LinearLayout>
</LinearLayout>
अब यह अपेक्षाकृत नीचे स्लाइड करता है। जाहिर है कि पैरेंट लेआउट के साथ कुछ चल रहा है ... जैसा कि getMeasuredHeight() सही मान देता है, यह सिर्फ एनीमेशन वास्तव में नहीं चलता है!
यह एनीमेशन वर्ग है, क्या मुझे कुछ मूर्खतापूर्ण याद आ रही है? शायद मैं हूँ!
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
public class DropDownAnim extends Animation {
int targetHeight;
View view;
boolean down;
public DropDownAnim(View view, int targetHeight, boolean down) {
this.view = view;
this.targetHeight = targetHeight;
this.down = down;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight;
if (down) {
newHeight = (int) (targetHeight * interpolatedTime);
} else {
newHeight = (int) (targetHeight * (1 - interpolatedTime));
}
Log.d("new height", String.valueOf(newHeight));
view.getLayoutParams().height = newHeight;
view.requestLayout();
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, ((View)view.getParent()).getWidth(), parentHeight);
}
@Override
public boolean willChangeBounds() {
return true;
}
}
कोई भी मदद शानदार होगी!
नहीं वास्तव में एक समाधान है, लेकिन जाने बटन वहां रहें और चले जाने के लिए इसकी दृश्यता निर्धारित करें। क्या यह इस तरह से काम करता है? – Urban
फिर मैं इसका परीक्षण करने के लिए इसे क्लिक नहीं कर पाऊंगा। मैं वहां एक और वस्तु रखूंगा और कोशिश करूँगा। –
नहीं, कोई पासा नहीं।यदि अगला भाई एनीमेशन का कारण बनने वाला बटन नहीं है, तो यह इसे निष्पादित नहीं करता है। कितना अजीब। यहां बहुत उलझन में है। –