调整 SuperToast 布局,使其不会横向占满屏幕
This commit is contained in:
1 parent
ed693d1742
commit
8848e712cc
2 files changed
+40
-31
No files matched your search
+36
-29
@@ -14,41 +14,48 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="60.0dp"
|
||||
android:minWidth="100.0dp"
|
||||
android:background="@color/toast_bg" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:paddingLeft="24.0dp"
|
||||
android:paddingRight="24.0dp" >
|
||||
|
||||
<!-- TODO I have no idear how to make some space in left and right when message is long -->
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingLeft="16dip"
|
||||
android:paddingStart="16dip" />
|
||||
android:minHeight="60.0dp"
|
||||
android:minWidth="100.0dp"
|
||||
android:background="@color/toast_bg" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingLeft="16dip"
|
||||
android:paddingStart="16dip"
|
||||
android:paddingRight="16dip"
|
||||
android:paddingEnd="16dip"
|
||||
android:singleLine="true"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp" />
|
||||
android:paddingStart="16dip" />
|
||||
|
||||
</RelativeLayout>
|
||||
<RelativeLayout
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:paddingLeft="16dip"
|
||||
android:paddingStart="16dip"
|
||||
android:paddingRight="16dip"
|
||||
android:paddingEnd="16dip"
|
||||
android:paddingTop="18.0dp"
|
||||
android:paddingBottom="18.0dp"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -22,6 +22,7 @@ import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@@ -55,14 +56,15 @@ public class SuperToast extends Toast {
|
||||
private void init() {
|
||||
LayoutInflater inflate = (LayoutInflater)
|
||||
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mMainView = (LinearLayout)inflate.inflate(R.layout.super_toast, null);
|
||||
FrameLayout view = (FrameLayout)inflate.inflate(R.layout.super_toast, null);
|
||||
mMainView = (LinearLayout)view.getChildAt(0);
|
||||
mIcon = (ImageView)mMainView.findViewById(R.id.icon);
|
||||
mMessage = (TextView)mMainView.findViewById(R.id.message);
|
||||
|
||||
mIcon.setVisibility(View.GONE);
|
||||
|
||||
setDuration(Toast.LENGTH_SHORT);
|
||||
setView(mMainView);
|
||||
setView(view);
|
||||
}
|
||||
|
||||
public SuperToast setIcon(int resId) {
|
||||
|
||||
Reference in new issue
Block a user