バックグラウンド
Androidの古いバージョンでも、linearLayoutの仕切り機能を使用しようとしています。
このため、actionBarSherlockには " com.actionbarsherlock.internal.widget.IcsLinearLayout "という優れたクラスがあることがわかりました。
問題
垂直方向を使用すると問題なく動作しますが、水平方向を使用すると、次のケースで仕切りが表示されません。
Android が API 17 以降で、デバイスが RTL 言語 (ヘブライ語など) を使用し、 android:supportsRtl="true" を設定した場合。これにより、一部の仕切りが表示され (一部は表示されない)、左側に空の仕切り (マージンなど) が表示されます。
さて、内部ビューを使用すべきではないことはわかっていますが、これはlinearLayoutsにとって非常に重要な機能であり、それに代わる優れた機能が見つかりません( HoloEverywhereは非常に重いライブラリであり、これ)。
使用例は次のとおりです。
activity_main.xml
<com.example.test.IcsLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@drawable/divider"
android:measureWithLargestChild="true"
android:orientation="horizontal"
android:showDividers="middle"
tools:context=".MainActivity" >
<View
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFff0000" />
<View
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFffff00" />
<View
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFff00ff" />
</com.example.test.IcsLinearLayout>
仕切り.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size
android:height="1dp"
android:width="1dp" />
<solid android:color="#FF000000" />
</shape>
繰り返しますが、垂直方向にある場合 (そして、子の幅と高さを正しく設定している場合) は、仕切りがうまく表示されます。
私が試したこと
新しいバージョンを無視し、古いバージョンにのみ適用するようにしました (バージョンをチェックし、新しい API の関数を呼び出さないようにすることで) が、役に立ちませんでした。
また、次のように、公式の Android コードから drawDividersHorizontal の一部をコピーしようとしました。
void drawDividersHorizontal(final Canvas canvas)
{
final int count=getChildCount();
boolean isLayoutRtl=false;
if(VERSION.SDK_INT>=VERSION_CODES.JELLY_BEAN_MR1)
isLayoutRtl=(getLayoutDirection()&View.LAYOUT_DIRECTION_RTL)!=0;
for(int i=0;i<count;i++)
{
final View child=getChildAt(i);
if(child!=null&&child.getVisibility()!=GONE)
if(hasDividerBeforeChildAt(i))
{
final LayoutParams lp=(LayoutParams)child.getLayoutParams();
final int position;
if(isLayoutRtl)
position=child.getRight()+lp.rightMargin;
else position=child.getLeft()-lp.leftMargin-mDividerWidth;
drawVerticalDivider(canvas,position);
}
}
if(hasDividerBeforeChildAt(count))
{
final View child=getChildAt(count-1);
int position;
if(child==null)
{
if(isLayoutRtl)
position=getPaddingLeft();
else position=getWidth()-getPaddingRight()-mDividerWidth;
}
else
{
final LayoutParams lp=(LayoutParams)child.getLayoutParams();
if(isLayoutRtl)
position=child.getLeft()-lp.leftMargin-mDividerWidth;
else position=child.getRight()+lp.rightMargin;
}
drawVerticalDivider(canvas,position);
}
}
質問
横向きでも機能させるにはどうすればよいですか?