我的ListView存在一个奇怪的问题,我在聊天适配器中使用它,它的Mainview非常深,但是它们的大部分可见性都消失了,所以基本上不是那么深,我怎么使用Spannable String生成器来过滤我的聊天,这是它的代码:
private static final Factory spannableFactory = Spannable.Factory
.getInstance();
private static final Map<Pattern, Integer> emoticons = new HashMap<Pattern, Integer>();
static {
System.out.println("Adding Patterns");
addPattern(emoticons, ":)", R.drawable.ic_beer);
addPattern(emoticons, ":-)", R.drawable.ic_file);
addPattern(emoticons,":O",R.drawable.antartica10);
// ...
}
private static void addPattern(Map<Pattern, Integer> map, String smile,
int resource) {
map.put(Pattern.compile(Pattern.quote(smile)), resource);
}
public static boolean addSmiles(Context context, Spannable spannable) {
boolean hasChanges = false;
for (Entry<Pattern, Integer> entry : emoticons.entrySet()) {
Matcher matcher = entry.getKey().matcher(spannable);
while (matcher.find()) {
boolean set = true;
for (ImageSpan span : spannable.getSpans(matcher.start(),
matcher.end(), ImageSpan.class))
if (spannable.getSpanStart(span) >= matcher.start()
&& spannable.getSpanEnd(span) <= matcher.end())
spannable.removeSpan(span);
else {
set = false;
break;
}
if (set) {
hasChanges = true;
spannable.setSpan(new ImageSpan(context, entry.getValue()),
matcher.start(), matcher.end(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
return hasChanges;
}
public static Spannable getSmiledText(Context context, CharSequence text) {
Spannable spannable = spannableFactory.newSpannable(text);
addSmiles(context, spannable);
return spannable;
}
这是我保存ListView的片段的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listViewchat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/form"
android:layout_alignParentTop="true"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
>
</ListView>
<RelativeLayout
android:id="@+id/form"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/bottom_write_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/message_bar" >
<EditText
android:id="@+id/TextFeild"
android:layout_width="0dip"
android:layout_height="45dp"
android:layout_margin="5sp"
android:layout_weight="0.13"
android:background="@drawable/message_field"
android:ems="10"
android:hint="Write here"
android:padding="5sp"
android:textColor="@color/textFieldColor" >
<requestFocus />
</EditText>
<Button
android:id="@+id/SendText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:background="@drawable/send_button"
android:paddingBottom="5sp"
android:paddingLeft="15sp"
android:paddingRight="15sp"
android:paddingTop="5sp"
android:text="Send"
android:textColor="#FFF" />
<Button
android:id="@+id/ImportFile"
android:layout_width="41dp"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:background="@drawable/send_button"
android:paddingBottom="5sp"
android:paddingLeft="15sp"
android:paddingRight="15sp"
android:paddingTop="5sp"
android:text="F"
android:textColor="#FFF" />
<Button
android:id="@+id/single_chat_record"
android:layout_width="41dp"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:background="@drawable/send_button"
android:paddingBottom="5sp"
android:paddingLeft="15sp"
android:paddingRight="15sp"
android:paddingTop="5sp"
android:text="R"
android:textColor="#FFF" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="@+id/MSGTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/VideoFrame"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/abc_ab_solid_light_holo">
<VideoView
android:id="@+id/VideoPlayer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
<Button
android:id="@+id/videodismiss"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:gravity="bottom"
/>
</FrameLayout>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@+id/audioframe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/abc_ab_solid_light_holo"
android:visibility="gone"
>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#75000000"
android:orientation="vertical"
android:paddingBottom="2dp"
android:paddingTop="5dp" >
<TextView
android:id="@+id/trackTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:singleLine="true"
android:text="@string/trackInitialValue"
android:textAppearance="?android:attr/textAppearanceLarge"
android:visibility="visible"
android:textSize="15sp"
/>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_margin="5dp"
android:background="#5033ff33" />
<LinearLayout
android:id="@+id/singlechat_musicplayer_artist_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingBottom="2dp"
android:paddingTop="2dp"
android:scaleType="fitCenter"
android:src="@drawable/artist24" />
<TextView
android:id="@+id/trackArtist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:singleLine="true"
android:text="@string/artistInitialValue"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="visible"
android:textSize="12sp"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/singlechat_musicplayer_album_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingBottom="2dp"
android:paddingTop="2dp"
android:scaleType="fitCenter"
android:src="@drawable/album24" />
<TextView
android:id="@+id/trackAlbum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="90dp"
android:singleLine="true"
android:text="@string/albumInitialValue"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="visible"
android:textSize="12sp"
/>
</LinearLayout>
<SeekBar
android:id="@+id/songprogressBar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:progressDrawable="@drawable/progress_bar_full" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="@drawable/header_bg100"
android:gravity="center_vertical" >
<TextView
android:id="@+id/trackDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="8dp"
android:layout_marginRight="15dp"
android:text="@string/durationInitialValue"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/trackPostionSeparator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/trackDuration"
android:layout_alignBaseline="@id/trackDuration"
android:text="@string/trackPostionSeparator"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/trackCurrPostion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/trackPostionSeparator"
android:layout_alignBaseline="@id/trackDuration"
android:text="@string/currPositionInitialValue"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<ImageView
android:id="@+id/playButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="@string/play"
android:paddingTop="2dp"
android:src="@drawable/play96" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true" >
<ImageView
android:id="@+id/separator"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="@drawable/separator" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<Button
android:id="@+id/audiodismiss"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Back"
android:layout_gravity="right"
/>
</FrameLayout>
</FrameLayout>
VideoPlayer和MusicPlayer图层是不可见的。我遇到的问题是按下按钮或从返回应用程序返回时的某些时间,我收到此错误:
09-20 05:52:19.019: E/AndroidRuntime(4934): FATAL EXCEPTION: main
09-20 05:52:19.019: E/AndroidRuntime(4934): java.lang.StackOverflowError
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.resolveTextDirection(View.java:13939)
09-20 05:52:19.019: E/AndroidRuntime(4934): at
android.view.View.getResolvedTextDirection(View.java:13923)
实际上我发现IME键盘的Upcoming和DownGoing动画导致问题,但仍然没有解决方案。是否有一些错误或问题是否还有其他?